Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSA加密 #31

Open
hapiman opened this issue Dec 27, 2017 · 0 comments
Open

RSA加密 #31

hapiman opened this issue Dec 27, 2017 · 0 comments

Comments

@hapiman
Copy link
Owner

hapiman commented Dec 27, 2017

'use strict'

const nodeRsa = require('node-rsa')

let privatePem = '私钥'
let publicPem = '公钥'
let text = '欲加密文本'

let publicKey = new nodeRsa(publicPem);
let privateKey = new nodeRsa(privatePem);

publicKey.setOptions({encryptionScheme: 'pkcs1'});
privateKey.setOptions({encryptionScheme: 'pkcs1'});

let encrypted = publicKey.encrypt(text, 'base64')
// iTGJGi3YWjPqrlTASjA+dB7oRwSYO50nToxkuSe+7dzZ6eC2uQE0tGk2TV+ouj9FDwdUmc/5yMBKP4Bvyan0+08yGlnl6yQMwvlQ0CagTwdzxdstMjfAReLC4JANcodW/+zB6H3K64WpLCRuQB0m0Ss1IxygM3I2Ut27gnlFhjY=
var decrypted = privateKey.decrypt(encrypted, 'utf8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant