rsaEncrypt.js 1.08 KB
Newer Older
xinzhedeai's avatar
xinzhedeai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min';
//import jsencrypt from 'jsencrypt'
//import crypto from 'crypto'
import encryption from './encryption'

// 密钥对生成 http://web.chacuo.net/netrsakeypair
/* Node env
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKgzvKMsX/l5eI+12W6reo5VDw5wOS380zdNc6HpmdRYvfwrM02GOKgvx8pJGaSNf7ZF7llofOwNVIaIrCOS6nECAwEAAQ==';
// 加密
export function encrypt(txt) {
	var hashCode = encryption.hex_sha1(txt);
	var encryptor = new JSEncrypt();
	encryptor.setPublicKey(publicKey) // 设置公钥
	return encryptor.encrypt(hashCode);
}; */

// eladmin
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD\n2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ==';
// 加密
export function encrypt(txt) {
	const encryptor = new JSEncrypt()
	encryptor.setPublicKey(publicKey) // 设置公钥
	return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}


// 解密
/* export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey)
  return encryptor.decrypt(txt)
} */