How to use the privateDecrypt function from crypto
Find comprehensive JavaScript crypto.privateDecrypt code examples handpicked from public code repositorys.
GitHub: stakwork/sphinx-relay
32 33 34 35 36 37 38 39 40 41
let finalDec = '' const n = Math.ceil(buf.length / BLOCK_SIZE) const arr = Array(n).fill(0) const privc = cert.priv(privateKey) arr.forEach((_, i) => { const b = crypto.privateDecrypt( { key: privc, padding: crypto.constants.RSA_PKCS1_PADDING, },
62
243
17
+ 3 other calls in file
GitHub: Tanver-Hasan/jose
28 29 30 31 32 33 34 35 36 37
return { wrapped: publicEncrypt({ key, oaepHash, padding }, payload) } } const unwrapKey = (padding, oaepHash, { [KEYOBJECT]: keyObject }, payload) => { const key = keyObject.asInput ? keyObject.asInput(false) : keyObject return privateDecrypt({ key, oaepHash, padding }, payload) } module.exports = (JWA) => { ['RSA1_5', 'RSA-OAEP', 'RSA-OAEP-256'].forEach((jwaAlg) => {
279
0
1
95 96 97 98 99 100 101 102 103 104
// read the private key: options.key = fs.readFileSync('private_key.pem', 'utf8'); // read the encrypted file: let input = fs.readFileSync(someFile); // decrypt it with the private key: let result = crypto.privateDecrypt(options, input); // print it: console.log(result.toString()); // clear the key: options.key = '';
35
30
4
GitHub: xofym/node-rsa
33 34 35 36 37 38 39 40 41 42
var padding = constants.RSA_PKCS1_OAEP_PADDING; if (options.encryptionScheme === 'pkcs1') { padding = constants.RSA_PKCS1_PADDING; } return crypto.privateDecrypt({ key: options.rsaUtils.exportKey('private'), padding: padding }, buffer); }
210
0
10
37 38 39 40 41 42 43 44 45
return enc.toString('base64'); }; rsaWrapper.decrypt = (privateKey, message) => { let enc = crypto.privateDecrypt({ key: privateKey, padding: crypto.RSA_PKCS1_OAEP_PADDING }, Buffer.from(message, 'base64'));
36
63
11
410 411 412 413 414 415 416 417 418 419 420
const decryptMetadataPrivateKey = (data, privateKey) => { return new Promise(async (resolve, reject) => { derKeyToPem(privateKey).then((key) => { try{ const decrypted = crypto.privateDecrypt({ key, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, oaepHash: "sha512" }, base64ToArrayBuffer(data))
24
118
8
GitHub: LinusU/webcrypto
154 155 156 157 158 159 160 161 162 163
} // 3-5. Attempt to decrypt using crypto lib try { data = Buffer.from(data) result = crypto.privateDecrypt({ key: key.handle, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING }, data)
16
0
3
88 89 90 91 92 93 94 95 96 97
}, plaintext ) } function rsaDecrypt(privateKey, message) { return crypto.privateDecrypt( { key: privateKey, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, oaepHash: 'sha256'
10
28
7
GitHub: linagora/TDrive
18 19 20 21 22 23 24 25 26 27
); } try { // privateDecrypt will throw an error with an invalid key crypto.privateDecrypt(key, encrypted); } catch (err) { throw new Error( `The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${ err.message
1
0
0
64 65 66 67 68 69 70 71 72 73 74
//RSA Decryption function rsaDecryptFromBase64(encryptedData, privateKey) { //private key and padding is passed //decrypts the encrypted Data using privateDecrypt function let decryptedText = crypto.privateDecrypt( { key: privateKey, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, oaepHash: "sha256",
0
0
0
0 1 2 3 4 5 6 7 8 9 10
var crypto = require('crypto') if (typeof crypto.publicEncrypt !== 'function') { crypto = require('./browser') } exports.publicEncrypt = crypto.publicEncrypt exports.privateDecrypt = crypto.privateDecrypt if (typeof crypto.privateEncrypt !== 'function') { exports.privateEncrypt = require('./browser').privateEncrypt } else {
0
0
0
+ 4 other calls in file
45 46 47 48 49 50 51 52 53 54 55
log.log("encypted data: ", encrypted.toString("base64")); return encrypted; } const decryptedData = function (privateKey, encryptedData) { const decrypted = crypto.privateDecrypt( { key: privateKey.toString(), passphrase: 'top-secret', // In order to decrypt the data, we need to specify the
0
0
0
39 40 41 42 43 44 45 46 47 48
const bufferToEncrypt = Buffer.from(input); const bufferPassword = Buffer.from('password'); let encryptedBuffer = crypto.publicEncrypt(rsaPubPem, bufferToEncrypt); let decryptedBuffer = crypto.privateDecrypt(rsaKeyPem, encryptedBuffer); assert.strictEqual(decryptedBuffer.toString(), input); decryptedBuffer = crypto.privateDecrypt(rsaPkcs8KeyPem, encryptedBuffer); assert.strictEqual(decryptedBuffer.toString(), input);
0
0
0
+ 59 other calls in file
69 70 71 72 73 74 75 76 77 78
encoding: 'hex' }, Buffer.from(ab2enc).toString('hex')); } let decryptedBuffer = crypto.privateDecrypt(rsaKeyPem, encryptedBuffer); const otherDecrypted = crypto.privateDecrypt(rsaKeyPem, otherEncrypted); assert.strictEqual(decryptedBuffer.toString(), input); assert.strictEqual(otherDecrypted.toString(), input); decryptedBuffer = crypto.privateDecrypt(rsaPkcs8KeyPem, encryptedBuffer);
0
0
0
+ 13 other calls in file
0 1 2 3 4 5 6 7 8 9 10
var crypto = require('crypto'); if (typeof crypto.publicEncrypt !== 'function') { crypto = require('./browser'); } exports.publicEncrypt = crypto.publicEncrypt; exports.privateDecrypt = crypto.privateDecrypt; if (typeof crypto.privateEncrypt !== 'function') { exports.privateEncrypt = require('./browser').privateEncrypt; } else {
0
0
0
+ 3 other calls in file
GitHub: mac2000/cryptography
3 4 5 6 7 8 9 10 11 12
const encrypted = Buffer.from(fs.readFileSync('protected.txt', 'utf8'), 'base64') const privateKey = crypto.createPrivateKey(fs.readFileSync('private.pem', 'utf8')) const decrypted = crypto.privateDecrypt({key: privateKey, padding: crypto.constants.RSA_PKCS1_PADDING}, Buffer.from(encrypted, 'base64')) // const decrypted = crypto.privateDecrypt(privateKey, Buffer.from(encrypted, 'base64')) console.log(decrypted.toString('utf8')) // crypto.constants.RSA_PKCS1_PADDING
0
0
1
+ 3 other calls in file
crypto.createHash is the most popular function in crypto (882 examples)