Lines Matching defs:const
3 const common = require('../common');
7 const assert = require('assert');
8 const {
27 const fixtures = require('../common/fixtures');
29 const publicPem = fixtures.readKey('rsa_public.pem', 'ascii');
30 const privatePem = fixtures.readKey('rsa_private.pem', 'ascii');
32 const publicDsa = fixtures.readKey('dsa_public_1025.pem', 'ascii');
33 const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
38 const TYPE = 'wrong_type';
69 const keybuf = randomBytes(32);
70 const key = createSecretKey(keybuf);
77 const exportedKey = key.export();
80 const plaintext = Buffer.from('Hello world', 'utf8');
82 const cipher = createCipheriv('aes-256-ecb', key, null);
83 const ciphertext = Buffer.concat([
87 const decipher = createDecipheriv('aes-256-ecb', key, null);
88 const deciphered = Buffer.concat([
97 const publicKey = createPublicKey(publicPem);
113 const privateKey = createPrivateKey(privatePem);
121 const jwk = {
150 const publicJwk = { kty: jwk.kty, e: jwk.e, n: jwk.n };
152 const publicKey = createPublicKey(publicPem);
158 const privateKey = createPrivateKey(privatePem);
165 const derivedPublicKey = createPublicKey(privateKey);
171 const publicKeyFromJwk = createPublicKey({ key: publicJwk, format: 'jwk' });
177 const privateKeyFromJwk = createPrivateKey({ key: jwk, format: 'jwk' });
185 const decryptedKey = createPublicKey({
199 for (const opt of [undefined, null, 'foo', 0, NaN]) {
207 for (const keyObject of [publicKey, derivedPublicKey, publicKeyFromJwk]) {
214 for (const keyObject of [privateKey, privateKeyFromJwk]) {
230 const publicDER = publicKey.export({
235 const privateDER = privateKey.export({
243 const plaintext = Buffer.from('Hello world', 'utf8');
244 const testDecryption = (fn, ciphertexts, decryptionKeys) => {
245 for (const ciphertext of ciphertexts) {
246 for (const key of decryptionKeys) {
247 const deciphered = fn(key, ciphertext);
321 const key = createPublicKey(publicPem).export({
377 const keyType = info.keyType;
380 const key = createPrivateKey(info.private);
391 const key = createPrivateKey({ key: info.jwk, format: 'jwk' });
402 for (const input of [
404 const key = createPublicKey(input);
410 const jwk = { ...info.jwk };
467 const { keyType, namedCurve } = info;
470 const key = createPrivateKey(info.private);
482 const key = createPrivateKey({ key: info.jwk, format: 'jwk' });
494 for (const input of [
496 const key = createPublicKey(input);
503 const jwk = { ...info.jwk };
544 const publicKey = createPublicKey(publicDsa);
552 const privateKey = createPrivateKey({
570 const publicPem = fixtures.readKey('rsa_pss_public_2048.pem');
571 const privatePem = fixtures.readKey('rsa_pss_private_2048.pem');
573 const publicKey = createPublicKey(publicPem);
574 const privateKey = createPrivateKey(privatePem);
579 const expectedKeyDetails = {
599 for (const key of [privatePem, privateKey]) {
601 for (const algo of ['sha1', 'sha256']) {
603 for (const saltLength of [undefined, 8, 10, 12, 16, 18, 20]) {
604 const signature = createSign(algo)
608 for (const pkey of [key, publicKey, publicPem]) {
609 const okay = createVerify(algo)
632 const publicPem = fixtures.readKey('rsa_pss_public_2048_sha1_sha1_20.pem');
633 const privatePem =
636 const publicKey = createPublicKey(publicPem);
637 const privateKey = createPrivateKey(privatePem);
643 const expectedKeyDetails = {
663 const publicPem =
665 const privatePem =
668 const publicKey = createPublicKey(publicPem);
669 const privateKey = createPrivateKey(privatePem);
677 for (const key of [privatePem, privateKey]) {
684 for (const saltLength of [8, 10, 12]) {
691 for (const saltLength of [undefined, 16, 18, 20]) {
692 const signature = createSign('sha256')
696 for (const pkey of [key, publicKey, publicPem]) {
697 const okay = createVerify('sha256')
710 const publicPem =
712 const privatePem =
715 const publicKey = createPublicKey(publicPem);
716 const privateKey = createPrivateKey(privatePem);
718 const expectedKeyDetails = {
738 for (const key of [privatePem, privateKey]) {
741 for (const algo of ['sha1', 'sha256']) {
748 const signature = createSign('sha512')
752 for (const pkey of [key, publicKey, publicPem]) {
753 const okay = createVerify('sha512')
765 const privateKey = createPrivateKey(privatePem);
779 const buffer = Buffer.from('Hello World');
780 const keyObject = createSecretKey(buffer);
789 const buffer = Buffer.from('Hello World');
790 const keyObject = createSecretKey(buffer);
799 const supported = ['prime256v1', 'secp256k1', 'secp384r1', 'secp521r1'];
802 const namedCurve = getCurves().find((curve) => !supported.includes(curve));
804 const keyPair = generateKeyPairSync('ec', { namedCurve });
805 const { publicKey, privateKey } = keyPair;
821 const first = Buffer.from('Hello');
822 const second = Buffer.from('World');
823 const keyObject = createSecretKey(first);
839 const first = generateKeyPairSync('ed25519');
840 const second = generateKeyPairSync('ed25519');
841 const secret = generateKeySync('aes', { length: 128 });
859 const first = generateKeyPairSync('ed25519');
860 const second = generateKeyPairSync('ed448');
869 const first = createSecretKey(Buffer.alloc(0));
870 const second = createSecretKey(new ArrayBuffer(0));
871 const third = createSecretKey(Buffer.alloc(1));
880 for (const key of ['', 'foo', null, undefined, true, Boolean]) {