mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
feat: generate key pair using ssh2 for right public key format
This commit is contained in:
1 parent
03b2993b56
commit
261c6fc029
6 files changed
+20
-15
No files matched your search
@@ -1,5 +1,9 @@
|
||||
import fs from 'fs'
|
||||
import { generateKeyPairSync } from 'crypto'
|
||||
import ssh2 from 'ssh2'
|
||||
|
||||
const {
|
||||
utils: { generateKeyPairSync },
|
||||
} = ssh2
|
||||
|
||||
type KeyPair = {
|
||||
privateKey: string
|
||||
@@ -24,16 +28,7 @@ export function loadOrCreateKeyPair(privateKeyPath: string): KeyPair {
|
||||
}
|
||||
|
||||
export function generateKeyPair(): KeyPair {
|
||||
const { privateKey, publicKey } = generateKeyPairSync('rsa', {
|
||||
modulusLength: 2048,
|
||||
publicKeyEncoding: {
|
||||
type: 'spki',
|
||||
format: 'pem',
|
||||
},
|
||||
privateKeyEncoding: {
|
||||
type: 'pkcs8',
|
||||
format: 'pem',
|
||||
},
|
||||
})
|
||||
const { private: privateKey, public: publicKey } =
|
||||
generateKeyPairSync('ed25519')
|
||||
return { privateKey, publicKey }
|
||||
}
|
||||
Reference in new issue
Block a user