How to use the privateEncrypt function from crypto

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

33
34
35
36
37
38
39
40
41
42
const kbits = bits / (1024);

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

4
5
6
7
8
9
10
11
12
13
var jsEngine = require('./js.js')(keyPair, options);

return {
    encrypt: function (buffer, usePrivate) {
        if (usePrivate) {
            return crypto.privateEncrypt({
                key: options.rsaUtils.exportKey('private'),
                padding: constants.RSA_PKCS1_PADDING
            }, buffer);
        } else {
fork icon210
star icon0
watch icon10

5
6
7
8
9
10
11
12
13
14
15
16
exports.privateDecrypt = crypto.privateDecrypt


if (typeof crypto.privateEncrypt !== 'function') {
  exports.privateEncrypt = require('./browser').privateEncrypt
} else {
  exports.privateEncrypt = crypto.privateEncrypt
}


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

+ 4 other calls in file

62
63
64
65
66
67
68
69
70
  key: rsaKeyPemEncrypted,
  passphrase: 'password'
}, encryptedBuffer);
assert.strictEqual(decryptedBufferWithPassword.toString(), input);

encryptedBuffer = crypto.privateEncrypt({
  key: rsaKeyPemEncrypted,
  passphrase: bufferPassword
}, bufferToEncrypt);
fork icon0
star icon0
watch icon0

+ 29 other calls in file

3
4
5
6
7
8
9
10
11
12
13
14


const fileContent = fs.readFileSync(`${process.env.TEXT_FILES_PATH}/data`, "utf8");
const privateKey = fs.readFileSync(`${process.env.DIR_KEYS}/priv_key`, "utf8");


// 
const encryptedString = crypto.privateEncrypt({
    key: privateKey,
    passphrase: process.env.PASSPHRASE
}, Buffer.from(fileContent)).toString("base64");

fork icon0
star icon0
watch icon0

5
6
7
8
9
10
11
12
13
14
15
16
exports.privateDecrypt = crypto.privateDecrypt;


if (typeof crypto.privateEncrypt !== 'function') {
  exports.privateEncrypt = require('./browser').privateEncrypt;
} else {
  exports.privateEncrypt = crypto.privateEncrypt;
}


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

+ 3 other calls in file