feat: generate key pair using ssh2 for right public key format

This commit is contained in:
Justin Lin committed 2024-10-14 11:34:53 +08:00
1 parent 03b2993b56
commit 261c6fc029
6 files changed
+20 -15

No files matched your search

+7 -12
View File
@@ -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 }
}