[node] add crypto.generateKeyPair (#30346)

This commit is contained in:
Gerhard Stöbich
2018-11-09 14:26:21 -08:00
committed by Andy
parent 766a66b46b
commit 23568c0bd7
2 changed files with 133 additions and 0 deletions
+32
View File
@@ -6483,6 +6483,38 @@ declare module "crypto" {
function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
namespace generateKeyPair {
function __promisify__(type: "rsa", options: RSAKeyPairOptions<'pem', 'pem'>): Promise<{ publicKey: string, privateKey: string }>;
function __promisify__(type: "rsa", options: RSAKeyPairOptions<'pem', 'der'>): Promise<{ publicKey: string, privateKey: Buffer }>;
function __promisify__(type: "rsa", options: RSAKeyPairOptions<'der', 'pem'>): Promise<{ publicKey: Buffer, privateKey: string }>;
function __promisify__(type: "rsa", options: RSAKeyPairOptions<'der', 'der'>): Promise<{ publicKey: Buffer, privateKey: Buffer }>;
function __promisify__(type: "dsa", options: DSAKeyPairOptions<'pem', 'pem'>): Promise<{ publicKey: string, privateKey: string }>;
function __promisify__(type: "dsa", options: DSAKeyPairOptions<'pem', 'der'>): Promise<{ publicKey: string, privateKey: Buffer }>;
function __promisify__(type: "dsa", options: DSAKeyPairOptions<'der', 'pem'>): Promise<{ publicKey: Buffer, privateKey: string }>;
function __promisify__(type: "dsa", options: DSAKeyPairOptions<'der', 'der'>): Promise<{ publicKey: Buffer, privateKey: Buffer }>;
function __promisify__(type: "ec", options: ECKeyPairOptions<'pem', 'pem'>): Promise<{ publicKey: string, privateKey: string }>;
function __promisify__(type: "ec", options: ECKeyPairOptions<'pem', 'der'>): Promise<{ publicKey: string, privateKey: Buffer }>;
function __promisify__(type: "ec", options: ECKeyPairOptions<'der', 'pem'>): Promise<{ publicKey: Buffer, privateKey: string }>;
function __promisify__(type: "ec", options: ECKeyPairOptions<'der', 'der'>): Promise<{ publicKey: Buffer, privateKey: Buffer }>;
}
}
declare module "stream" {
+101
View File
@@ -1555,6 +1555,107 @@ async function asyncStreamPipelineFinished() {
},
});
}
{
crypto.generateKeyPair('rsa', {
modulusLength: 123,
publicKeyEncoding: {
format: 'der',
type: 'pkcs1',
},
privateKeyEncoding: {
cipher: 'some-cipher',
format: 'pem',
passphrase: 'secret',
type: 'pkcs8',
},
}, (err: NodeJS.ErrnoException | null, publicKey: Buffer, privateKey: string) => {});
crypto.generateKeyPair('dsa', {
modulusLength: 123,
divisorLength: 123,
publicKeyEncoding: {
format: 'pem',
type: 'spki',
},
privateKeyEncoding: {
cipher: 'some-cipher',
format: 'der',
passphrase: 'secret',
type: 'pkcs8',
},
}, (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: Buffer) => {});
crypto.generateKeyPair('ec', {
namedCurve: 'curve',
publicKeyEncoding: {
format: 'pem',
type: 'pkcs1',
},
privateKeyEncoding: {
cipher: 'some-cipher',
format: 'pem',
passphrase: 'secret',
type: 'pkcs8',
},
}, (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {});
}
{
const generateKeyPairPromisified = util.promisify(crypto.generateKeyPair);
const rsaRes: Promise<{
publicKey: Buffer;
privateKey: string;
}> = generateKeyPairPromisified('rsa', {
modulusLength: 123,
publicKeyEncoding: {
format: 'der',
type: 'pkcs1',
},
privateKeyEncoding: {
cipher: 'some-cipher',
format: 'pem',
passphrase: 'secret',
type: 'pkcs8',
},
});
const dsaRes: Promise<{
publicKey: string;
privateKey: Buffer;
}> = generateKeyPairPromisified('dsa', {
modulusLength: 123,
divisorLength: 123,
publicKeyEncoding: {
format: 'pem',
type: 'spki',
},
privateKeyEncoding: {
cipher: 'some-cipher',
format: 'der',
passphrase: 'secret',
type: 'pkcs8',
},
});
const ecRes: Promise<{
publicKey: string;
privateKey: string;
}> = generateKeyPairPromisified('ec', {
namedCurve: 'curve',
publicKeyEncoding: {
format: 'pem',
type: 'pkcs1',
},
privateKeyEncoding: {
cipher: 'some-cipher',
format: 'pem',
passphrase: 'secret',
type: 'pkcs8',
},
});
}
}
//////////////////////////////////////////////////