How to use the publicDecrypt function from crypto

Find comprehensive JavaScript crypto.publicDecrypt code examples handpicked from public code repositorys.

34
35
36
37
38
39
40
41
42
43

  const privateKey = RSA_PrivatePem[keylen];
  const publicKey = RSA_PublicPem[keylen];
  for (let i = 0; i < n; i++) {
    const enc = crypto.privateEncrypt(privateKey, message);
    crypto.publicDecrypt(publicKey, enc);
  }

  bench.end(kbits);
}
fork icon0
star icon3
watch icon2

23
24
25
26
27
28
29
30
31
32
    }
},

decrypt: function (buffer, usePublic) {
    if (usePublic) {
        return crypto.publicDecrypt({
            key: options.rsaUtils.exportKey('public'),
            padding: constants.RSA_PKCS1_PADDING
        }, buffer);
    } else {
fork icon210
star icon0
watch icon10

11
12
13
14
15
16
17
18
}


if (typeof crypto.publicDecrypt !== 'function') {
  exports.publicDecrypt = require('./browser').publicDecrypt
} else {
  exports.publicDecrypt = crypto.publicDecrypt
}
fork icon0
star icon0
watch icon0

+ 4 other calls in file

67
68
69
70
71
72
73
74
75
76
encryptedBuffer = crypto.privateEncrypt({
  key: rsaKeyPemEncrypted,
  passphrase: bufferPassword
}, bufferToEncrypt);

decryptedBufferWithPassword = crypto.publicDecrypt({
  key: rsaKeyPemEncrypted,
  passphrase: bufferPassword
}, encryptedBuffer);
assert.strictEqual(decryptedBufferWithPassword.toString(), input);
fork icon0
star icon0
watch icon0

+ 35 other calls in file

11
12
13
14
15
16
17
18
}


if (typeof crypto.publicDecrypt !== 'function') {
  exports.publicDecrypt = require('./browser').publicDecrypt;
} else {
  exports.publicDecrypt = crypto.publicDecrypt;
}
fork icon0
star icon0
watch icon0

+ 3 other calls in file

30
31
32
33
34
35
36
37
38
39
40
41


const encryptedString = crypto.privateEncrypt({
  key: privateKey,
  passphrase: 'abcdef'
}, Buffer.from(msg)).toString('base64');
const decryptedString = crypto.publicDecrypt(publicKey, Buffer.from(encryptedString, 'base64')).toString();
console.log(`Encrypted: ${encryptedString}`);
console.log(`Decrypted: ${decryptedString}`);


assert.notStrictEqual(encryptedString, '');
fork icon0
star icon0
watch icon0

+ 3 other calls in file

2
3
4
5
6
7
8
9
10
11
12
13
14
15
require('dotenv').config();


const encrypteData = fs.readFileSync(`${process.env.TEXT_FILES_PATH}/encrypted_by_priv`, "utf8");
const pubKey = fs.readFileSync(`${process.env.DIR_KEYS}/pub_key`, "utf8");


const decryptedString = crypto.publicDecrypt(pubKey, Buffer.from(encrypteData, "base64")).toString();


fs.writeFileSync(`${process.env.TEXT_FILES_PATH}/decrypted_by_priv`, decryptedString);


process.env.DEBUG == 1 && console.log(decryptedString);
fork icon0
star icon0
watch icon0