1  /* base64 加解密
2 */
3 export let Base64 = require('js-base64').Base64
4
5 /* md5 加解密
6 */
7 export let crypto = require('crypto');
8 export let md5 = require('js-md5');
9 export let CryptoJS = require('crypto-js');
10 export let MD5 = CryptoJS.MD5;
11 /*
12 *引入jsencrypt实现数据RSA加密
13 */
14 import JSEncrypt from 'jsencrypt';
15 // jsencrypt.js处理长文本数据时报错 Message too long for RSA
16 // encryptlong是基于jsencrypt扩展的长文本分段加解密功能。
17 import Encrypt from "encryptlong";
18 // rsa sign
19 import jsrsasign from 'jsrsasign'
20
21 // Message Digest algorithm 5,信息摘要算法
22 // alglorithm:md5、sha1、sha256
23 export function Md5(plainText, alglorithm, encoding){
24 const hash = crypto.createHash(alglorithm)
25 hash.update(plainText);//加密内容
26 return hash.digest(encoding);//密文
27 }
28
29 //Hash Message Authentication Code,散列消息鉴别码
30 //Secure Hash Algorithm,安全散列算法
31 // alglorithm:md5、sha256、sha1
32 export function HMac(plainText, secretKey,alglorithm, encoding){
33 const hmac= crypto.createHmac(alglorithm, secretKey);
34 const cipherText= hmac.update(plainText);//加密内容
35 return cipherText.digest(encoding);//密文
36 }
37
38 //Data Encryption Standard,数据加密算法
39 // DES/DES3/AES 加密, key与iv长度必须是8的倍数
40 //mode:CryptoJS.mode.CBC、CryptoJS.mode.ECB、CryptoJS.mode.CFB
41 //padding:CryptoJS.pad.ZeroPadding、CryptoJS.pad.Pkcs7、CryptoJS.pad.NoPadding
42 export function encrypt ( algorithm, plainText,key, iv, mode, padding, isBase64) {
43 key = key ? key : "abcdefghijklmnop";
44 iv = iv ? iv : "0102030405060708";
45
46 const keyHex = CryptoJS.enc.Utf8.parse(key);
47 const ivHex = CryptoJS.enc.Utf8.parse(iv);
48 const option = { iv:keyHex,mode: mode, padding: padding }
49 let encrypted = null ;
50 if(algorithm === "TripleDES"){
51 encrypted = CryptoJS.TripleDES.encrypt(plainText, keyHex, option)
52 }else if(algorithm === "DES"){
53 encrypted = CryptoJS.DES.encrypt(plainText, keyHex, option)
54 }
55 else if(algorithm === "AES"){
56 encrypted = CryptoJS.AES.encrypt(plainText, keyHex, option)
57 }
58 return isBase64?CryptoJS.enc.Base64.stringify(encrypted.ciphertext):encrypted.ciphertext.toString();
59 }
60
61 // DES/DES3/AES解密,key与iv长度必须是8的倍数
62 export function decrypt (algorithm,cipherText,key, iv, mode, padding, isBase64) {
63 key = key ? key : "abcdefghijklmnop";
64 iv = iv ? iv : "0102030405060708";
65
66 const keyHex = CryptoJS.enc.Utf8.parse(key);
67 const ivHex = CryptoJS.enc.Utf8.parse(iv);
68 const decryptText = isBase64? CryptoJS.enc.Base64.parse(cipherText):cipherText;
69 const textHex = { ciphertext: isBase64?decryptText:CryptoJS.enc.Hex.parse(decryptText) }
70 const option = { iv:ivHex,mode: mode, padding: padding }
71 let decrypted = null;
72 if(algorithm === "TripleDES"){
73 decrypted = CryptoJS.TripleDES.decrypt(textHex, keyHex, option);
74 }else if(algorithm === "DES"){
75 decrypted = CryptoJS.DES.decrypt(textHex, keyHex, option);
76 }
77 else if(algorithm === "AES"){
78 decrypted = CryptoJS.AES.decrypt(textHex, keyHex, option);
79 }
80 return decrypted.toString(CryptoJS.enc.Utf8);
81 }
82
83 /** RSA 加密过程
84 * (1)A生成一对密钥(公钥和私钥),私钥不公开,A自己保留。公钥为公开的,任何人可以获取。
85 * (2)A传递自己的公钥给B,B用A的公钥对消息进行加密。
86 * (3)A接收到B加密的消息,利用A自己的私钥对消息进行解密。
87 * 在这个过程中,只有2次传递过程,第一次是A传递公钥给B,第二次是B传递加密消息给A,即使都被敌方截获,也没有危险性。
88 * 因为只有A的私钥才能对消息进行解密,防止了消息内容的泄露。
89 * 使用方法
90 * 客户端初始化访问服务器端时,服务器端会生成一对RSA对,及公钥和密钥。
91 * 如果前端只需要将要传给后端的数据进行加密后传输,那么前端可以只要公钥,通过公钥对要传输的参数进行加密后把加密的字符串发给后端,后端取出保存的密码种子或者直接保存的私钥,采用私钥对加密字符串进行解密,得到明文。
92 * 如果前端要获取后端传过来的已经加密后的字符串,并且解密使用,那么前端就需要拿到RSA对立面的私钥进行解密后使用了。
93 * */
94 /* JSEncrypt 公钥加密 padding:pkcs1pad2 */
95 export function RsaJSEncrypt(plainText,publicKey) {
96 const jsencrypt = new JSEncrypt({
97 default_key_size: 1024
98 });
99 jsencrypt.setPublicKey(publicKey);
100 // 如果是对象/数组的话,需要先JSON.stringify转换成字符串
101 // 处理中文乱码,服务器端:String result = java.net.URLDecoder.decode(cipherText ,"UTF-8");
102 const cipherText = encodeURIComponent(jsencrypt.encrypt(plainText));
103 return cipherText;
104 }
105
106 /* JSEncrypt 私钥解密 padding:pkcs1pad2 */
107 export function RsaJSDecrypt(cipherText,privateKey) {
108 const jsencrypt = new JSEncrypt({
109 default_key_size: 1024
110 });
111 jsencrypt.setPrivateKey(privateKey);
112 return jsencrypt.decrypt(decodeURIComponent(cipherText));
113 }
114
115 /* 长文本分段加密 */
116 export function RsaEncrypt(plainText,publicKey) {
117 const encryptor = new Encrypt();
118 encryptor.setPublicKey(publicKey);
119 // 处理中文乱码,服务器端:String result = java.net.URLDecoder.decode(cipherText ,"UTF-8");
120 const cipherText = encodeURIComponent(encryptor.encryptLong(plainText));
121 return cipherText;
122 }
123
124 /* 长文本分段解密 */
125 export function RsaDecrypt(cipherText,privateKey) {
126 var encryptor = new Encrypt();
127 encryptor.setPrivateKey(privateKey);
128 return encryptor.decryptLong(decodeURIComponent(cipherText));
129 }
130
131 // 获取签名 privateKey_s 服务器端的私钥
132 export function RsaSign(plainText,privateKey_s,format_key, alglorithm,isBase64)
133 {
134 // 生成签名对象
135 let sign = genSign(privateKey_s,format_key, alglorithm);
136
137 plainText = genDigest(plainText,alglorithm);
138 sign.updateString(plainText);
139
140 // +号服务器端不识别,url编码
141 return isBase64? encodeURIComponent(jsrsasign.hextob64(sign.sign())):encodeURIComponent(sign.sign());
142 }
143
144 // 验证签名 publicKey_s 服务器端的公钥
145 // alglorithm: SHA1withRSA、MD5withRSA、SHA256withRSA、 SHA384withRSA、SHA512withRSA、RIPEMD160withRSA
146 // format_key: PKCS#1、PKCS#5、PKCS#8
147 /*
148 * PKCS#1:定义RSA公开密钥算法加密和签名机制,主要用于组织PKCS#7中所描述的数字签名和数字信封。
149 * PKCS#3:定义Diffie-Hellman密钥交换协议。
150 * PKCS#5:描述一种利用从口令派生出来的安全密钥加密字符串的方法。使用MD2或MD5 从口令中派生密钥,并采用DES-CBC模式加密。主要用于加密从一个计算机传送到另一个计算机的私人密钥,不能用于加密消息[24]。
151 * PKCS#6:描述了公钥证书的标准语法,主要描述X.509证书的扩展格式。
152 * PKCS#7:定义一种通用的消息语法,包括数字签名和加密等用于增强的加密机制,PKCS#7与PEM兼容,所以不需其他密码操作,就可以将加密的消息转换成PEM消息[26]。
153 * PKCS#8:描述私有密钥信息格式,该信息包括公开密钥算法的私有密钥以及可选的属性集等。
154 * PKCS#9:定义一些用于PKCS#6证书扩展、PKCS#7数字签名和PKCS#8私钥加密信息的属性类型。
155 * PKCS#10:描述证书请求语法。
156 * PKCS#11:称为Cyptoki,定义了一套独立于技术的程序设计接口,用于智能卡和PCMCIA卡之类的加密设备。
157 * PKCS#12:描述个人信息交换语法标准。描述了将用户公钥、私钥、证书和其他相关信息打包的语法。
158 * PKCS#13:椭圆曲线密码体制标准。
159 * PKCS#14:伪随机数生成标准。
160 * PKCS#15:密码令牌信息格式标准。
161 */
162 export function RsaVerifySign(plainText,signedText,publicKey_s,format_key, alglorithm,isBase64)
163 {
164 // 生成签名
165 let verifySign = genSign(publicKey_s,format_key, alglorithm);
166 // 根据明文生成摘要
167 let digestText = genDigest(plainText,alglorithm);
168
169 verifySign.updateString(digestText);
170
171 return verifySign.verify(isBase64?jsrsasign.b64tohex(decodeURIComponent(signedText)):decodeURIComponent(signedText));
172 }
173
174 // 根据明文生成摘要
175 //SHA1withRSA、MD5withRSA、SHA256withRSA、 SHA384withRSA、SHA512withRSA、RIPEMD160withRSA
176 export function genDigest(plainText,alglorithm, ){
177 let option = { "alg": alglorithm.split('w')[0], "prov":"cryptojs/jsrsa", }
178 let text = new jsrsasign.KJUR.crypto.MessageDigest(option); // 摘要
179 text.updateString(plainText);
180 return text.digest();
181 }
182
183 /* 生成rsa签名对象
184 * */
185 export function genSign(RsaKey_s,format_key, alglorithm)
186 {
187 //私钥要写开头和结束
188 // var private_key = '-----BEGIN PRIVATE KEY-----' + privateKey_s + '-----END PRIVATE KEY-----'
189 // 读取解析pem格式的秘钥, 生成秘钥实例 (RSAKey)
190 let rsaKey = new jsrsasign.RSAKey();
191 if (format_key === "PKCS#1" || format_key === "PKCS#5"|| format_key === "PKCS#7"|| format_key === "PKCS#8") {
192 rsaKey = jsrsasign.KEYUTIL.getKey(RsaKey_s);
193 // rsaSign.readPrivateKeyFromPEMString(privateKey_s);
194 }
195
196 let option= {
197 "alg":alglorithm,
198 "prov":"cryptojs/jsrsa",
199 "prvkeypem": rsaKey
200 };
201
202 let sign = new jsrsasign.KJUR.crypto.Signature(option);
203 sign.init(rsaKey);
204
205 return sign;
206 }

测试代码:

  1    // 测试工具:http://www.1818288.com/
2 console.log("12345678汉字abcdef,md5="+this.$md5("12345678汉字abcdef"));
3 console.log("12345678,MD5="+this.$MD5("12345678"));
4 console.log("12345678,Md5="+this.$Md5("12345678","md5","hex"));
5 console.log("12345678,HMac-MD5="+this.$HMac("12345678汉字abcdef","abcdef","md5","hex"));
6 console.log("12345678,enDES="+this.$Encrypt("DES","12345678","abcdef","abcdef",this.$CryptoJS.mode.CBC,this.$CryptoJS.pad.ZeroPadding,true));
7 console.log("12345678,deDES="+this.$Decrypt("DES","CQlZsExZRQM=","abcdef","abcdef",this.$CryptoJS.mode.CBC,this.$CryptoJS.pad.ZeroPadding,true));
8
9 console.log("12345678,enDES3="+this.$Encrypt("TripleDES","12345678","abcdef","abcdef",this.$CryptoJS.mode.ECB,this.$CryptoJS.pad.Pkcs7,true));
10 console.log("12345678,deDES3="+this.$Decrypt("TripleDES","Wb6LDNctz2HpGd1QX22oNQ==","abcdef","abcdef",this.$CryptoJS.mode.ECB,this.$CryptoJS.pad.Pkcs7,true));
11
12 console.log("12345678,enAES="+this.$Encrypt("AES","12345678","","",this.$CryptoJS.mode.ECB,this.$CryptoJS.pad.Pkcs7,false));
13 console.log("12345678,deAES="+this.$Decrypt("AES","5a9906baab69bdcd17a0f925cbb3dbb3","","",this.$CryptoJS.mode.ECB,this.$CryptoJS.pad.Pkcs7,false));
14
15 console.log("12345678,enAES="+this.$Encrypt("AES","12345678","","",this.$CryptoJS.mode.ECB,this.$CryptoJS.pad.Pkcs7,true));
16 console.log("12345678汉字abcdef,deAES="+this.$Decrypt("AES","WpkGuqtpvc0XoPkly7Pbsw==","","",this.$CryptoJS.mode.ECB,this.$CryptoJS.pad.Pkcs7,true));
17
18
19
20
21 console.log("12345678汉字abcdef,RSAEn_pubK="+this.$RsaEncrypt("12345678汉字abcdef","MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgFrtUneGIrf/hc7l9JUR+OCCDWqq\n" +
22 "ttX2pItsbg0fpZ6Zl0rCoZwuaRc5ltoVhIPvT2HEUYJrUmNwamtfXqZaxkvOtxpc\n" +
23 "GWB8nR3r9XTSE3/iuI7jMvXqP5HiWWoiT8IKwxaa3P5pu5UF5q/2t+/8XGeiGAoc\n" +
24 "WLiZ/HPpeZyQVUfXAgMBAAE="));
25
26 console.log("12345678汉字abcdef,RSADe_priK="+this.$RsaDecrypt(
27 "LbBdgV0HR0hmA1QTLTQdVugBlc%2FmmuAXJ51aTZnMukv5jlCBftVRWmyjk1UUntLzSRZV0J6arcbwv0i7qoLLgpYWQQfn700QcS0hp5GNyFxshZf%2FOHdJxzRcpSoCd7%2B%2F9NpAChLYcWYRBynHRZXXHb9fK6rDrXLK%2FIkBDaQItTM%3D","MIICWgIBAAKBgFrtUneGIrf/hc7l9JUR+OCCDWqqttX2pItsbg0fpZ6Zl0rCoZwu\n" +
28 "aRc5ltoVhIPvT2HEUYJrUmNwamtfXqZaxkvOtxpcGWB8nR3r9XTSE3/iuI7jMvXq\n" +
29 "P5HiWWoiT8IKwxaa3P5pu5UF5q/2t+/8XGeiGAocWLiZ/HPpeZyQVUfXAgMBAAEC\n" +
30 "gYAbawi9BfOeLCz7MJhKAzta55yIF6Y+ars/V5jv2CUm6AWZA4ub/tqtqC324Rou\n" +
31 "dpEnV/2EKDyVw6YzbnSqESFOCVNYOslqSLhSStkuvBYo3Tr1/8ITt1JKxcqS6Lix\n" +
32 "VVp4zl+MgBvYNOv1pbubsc76lMB1TirFN6U0iFsPKuBrgQJBALTqGJjbgI/Idvsi\n" +
33 "Z5ycE3kyD+ZLOYCDY3/GKh8xcD93iXRIj5AY4vA6Tqnb56eDY4GvXGEQaJpNAJ9z\n" +
34 "Ukq4G6ECQQCAqjEfELqDA2dLdV9fojYxq1j/PGlBUWlt0+8cEsOBTbMfD9Kt5diM\n" +
35 "b1Ut213I2z07ZFNHDouBOK8x4iDYanB3AkASchPT8f1nq47GCDn8M8Wgg8QvPNg+\n" +
36 "DCdm7bN5vratIej33DYXARKSX7+Jfgxeffz1SgXnN58SrGs11rI7QA5BAkB0BwZd\n" +
37 "GVzYoM0ZwzLKryFoETkkknnoqV4F6MUL7+/WPxd0v3Qh1dA+dHe/7r7YTr0dPg/L\n" +
38 "WFZ9pXx344/zGalpAkB8QBNZej44DU+nAi6KQVEbLxOps1BbyzzWfXI2uQRR+w52\n" +
39 "ABLacpwutsHC8jLjUDaCLfFUaEnpkBWW8u0pI54v"));
40
41
42 console.log("12345678汉字abcdef,RSAJSEn_pubK="+this.$RsaJSEncrypt("12345678汉字abcdef","MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNpEYv5DxAXWOg0HA1y0DROLiKfHTZJx/4TTWhrVNDSgNeR4iVT7fekbhRDYy0oHVDAS8Sy6yJDqMAPjRNmjrICgVuMwYzwXg2LRNy6SrB79DOz5X5vBPP6Lc+8eNt4mm0S+I1sba3tyueTXPaA9aMCyJjebKrsxwa8rG9K/OlqwIDAQAB"));
43
44 console.log("12345678汉字abcdef,RSAJSDe_priK="+this.$RsaJSDecrypt("DryU8wEn2yEG5HlkaJ2WeR5QYh%2FLhvMU3IwUsrN1OufDK5jlkSjMufgR%2BUruyTutj5N7r7MxXLXOH11VK%2BzBdr%2BIbK9Du54vQGhj2aERIUYqCKp0tk02qhCXWwl7XDYeusiFfvQ4J%2Fr%2BrEZolk%2FdA4WxOtq7QJf59fhPrxpf4YI%3D","MIICXQIBAAKBgQDNpEYv5DxAXWOg0HA1y0DROLiKfHTZJx/4TTWhrVNDSgNeR4iV\n" +
45 "T7fekbhRDYy0oHVDAS8Sy6yJDqMAPjRNmjrICgVuMwYzwXg2LRNy6SrB79DOz5X5\n" +
46 "vBPP6Lc+8eNt4mm0S+I1sba3tyueTXPaA9aMCyJjebKrsxwa8rG9K/OlqwIDAQAB\n" +
47 "AoGAPQoe30ZS8BQIZ4qXVBBhy/iXJlws3uwzHCPm4HevOFD20PxQuWkxPbppSH3K\n" +
48 "Hy9lvx7R1zVnoEMc9QyBv+sguQkNir722Hk8+BhMXxgb0eZPsSBUgXQmciHscRix\n" +
49 "52myI/tRRSbpuW/Qx4TYDeP/xUvDOgx4XnJ8v5Dy5bblFNkCQQD83ldtZpJHBsZ3\n" +
50 "rzzU+4xkUsA5W7rMmNK94N37Cu2hoFofk/9gfyG2BCDCUwBSfeQWJk0U2RaEsItm\n" +
51 "CBqn0cYFAkEA0DA2IBp5ECUDJhmdmgWfqi/NZGwLvBedWFY9hdQJ0auF3wOTeVSI\n" +
52 "fs1oBM+DKmHxb1oavZ8MaYFx6tQ2LFhb7wJAJV1lZdEGRGCH6x+FyaLx99ESfmdD\n" +
53 "jv/2BAC6TGItAvkC2C+ySLwAazjo7k39ejMIBQ3bzfzWCv1bW9ROvAWPUQJBAIIf\n" +
54 "QBU8tqJSn+82X30fOrZiflvf9E2x7NSDwpxc9W4paNkFIS3amh23QOaQ1Qiugvr4\n" +
55 "NHKEcHuZPpxp2xpId90CQQDeT8TK9ClvWutbj8fpSYGDFyyaf1qLPwBNpozXUMGh\n" +
56 "hNuOF+69LlAeH5p26omFjQUMfk7r0LjDdBrcoRhpbmkG"));
57
58
59 console.log("12345678汉字abcdef,RSASign_priK="+this.$RsaSign("12345678汉字abcdef","-----BEGIN PRIVATE KEY-----\n" +
60 "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOihfrud6pbH6y9m\n" +
61 "MGpG870wcZyKqwmedUmQH1cwsyOiJZZib0J4IlxRq6yTAuLRnXHM1JBnvvJl6oBH\n" +
62 "tvM6vSj6kSDY0SCuoARdp1oJH7BXLTcEVXIbGxD+/6ZcapydzcnBMtkHpG+pgf9c\n" +
63 "lf57z/aqewEAq00Z+rH+yWuyggITAgMBAAECgYEAnacEeiWVG8Y0jpTUbtHS0P4J\n" +
64 "oKshKo2mssnnU3F/lcCHdJkVCZjcwG/gxj2DETA5YSwNSifk8eU7vN/dDo1aLyZn\n" +
65 "+qc9rot+jHW+z8hXHWm+RbC8CkD7KMjd2RlRBcnSXieoUqqKyrwYL2JPecG22CFp\n" +
66 "QcvbAPT0ITor0lKNt4ECQQD7OGHxzM4DfG+tXj3RvWgk7I6lcHL4s7ad3hdkjkVe\n" +
67 "x+fHKybiCzl4o9dXS9iObw4xg54k7sKYs+S+6AsNKlazAkEA7Q6Rscpocw+dYQMv\n" +
68 "SdLIwB3eqUkcVxbvj9C/hFm5LqzvAMhcGQBp4Hp9OHILuqEYqFxuyIbCOyhbBJMo\n" +
69 "bBJXIQJBAM74F7FnYv76QOObNeEbY7av8aGZMA93t+b991XP5JT+qxSql4E5cCLV\n" +
70 "EO+JvCM0mYPvhJW24zl9U+J4N8qj7AMCQA9VROk6DV174hMXUKS2xJNgmzlZ6EJd\n" +
71 "0mr79pdJ8mdpeiAT1ZksZKzHX3gaMFYG+4BQUj4YMVIAPzrhhdjPquECQQDBFWVi\n" +
72 "ByzngHyXCuVpDN3FKZ26Cnqt8mY2kW8N+4/okQ+rPzxt86TywPerIGR1qAl5PgDS\n" +
73 "gMZzSWvMDuT8369m\n" +
74 "-----END PRIVATE KEY-----","PKCS#8","MD5withRSA",true));
75
76
77 console.log("12345678汉字abcdef,RSAVerifySign_pubK="+this.$RsaVerifySign("12345678汉字abcdef","VLFvc958umN%2FORw4Bb9kzsePgaar5gyW8VWpoAqETZJYKsulZFdBHT%2BQihD%2BEXufg7Ml%2BYp1gxtK5BEVWdfBS39v%2FRDGM8kYTz9aSi8HiSPAylm6d8KkqY61aXy%2F2GX%2FuRgycjRFklo5w9W8irYXELSXeBJFeEQmgsE3hMQIui4%3D","-----BEGIN PUBLIC KEY-----\n" +
78 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDooX67neqWx+svZjBqRvO9MHGc\n" +
79 "iqsJnnVJkB9XMLMjoiWWYm9CeCJcUauskwLi0Z1xzNSQZ77yZeqAR7bzOr0o+pEg\n" +
80 "2NEgrqAEXadaCR+wVy03BFVyGxsQ/v+mXGqcnc3JwTLZB6RvqYH/XJX+e8/2qnsB\n" +
81 "AKtNGfqx/slrsoICEwIDAQAB\n" +
82 "-----END PUBLIC KEY-----","PKCS#8","MD5withRSA",true));
83
84
85 console.log("12345678汉字abcdef,RSASign_priK="+this.$RsaSign("12345678汉字abcdef","-----BEGIN PRIVATE KEY-----\n" +
86 "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOihfrud6pbH6y9m\n" +
87 "MGpG870wcZyKqwmedUmQH1cwsyOiJZZib0J4IlxRq6yTAuLRnXHM1JBnvvJl6oBH\n" +
88 "tvM6vSj6kSDY0SCuoARdp1oJH7BXLTcEVXIbGxD+/6ZcapydzcnBMtkHpG+pgf9c\n" +
89 "lf57z/aqewEAq00Z+rH+yWuyggITAgMBAAECgYEAnacEeiWVG8Y0jpTUbtHS0P4J\n" +
90 "oKshKo2mssnnU3F/lcCHdJkVCZjcwG/gxj2DETA5YSwNSifk8eU7vN/dDo1aLyZn\n" +
91 "+qc9rot+jHW+z8hXHWm+RbC8CkD7KMjd2RlRBcnSXieoUqqKyrwYL2JPecG22CFp\n" +
92 "QcvbAPT0ITor0lKNt4ECQQD7OGHxzM4DfG+tXj3RvWgk7I6lcHL4s7ad3hdkjkVe\n" +
93 "x+fHKybiCzl4o9dXS9iObw4xg54k7sKYs+S+6AsNKlazAkEA7Q6Rscpocw+dYQMv\n" +
94 "SdLIwB3eqUkcVxbvj9C/hFm5LqzvAMhcGQBp4Hp9OHILuqEYqFxuyIbCOyhbBJMo\n" +
95 "bBJXIQJBAM74F7FnYv76QOObNeEbY7av8aGZMA93t+b991XP5JT+qxSql4E5cCLV\n" +
96 "EO+JvCM0mYPvhJW24zl9U+J4N8qj7AMCQA9VROk6DV174hMXUKS2xJNgmzlZ6EJd\n" +
97 "0mr79pdJ8mdpeiAT1ZksZKzHX3gaMFYG+4BQUj4YMVIAPzrhhdjPquECQQDBFWVi\n" +
98 "ByzngHyXCuVpDN3FKZ26Cnqt8mY2kW8N+4/okQ+rPzxt86TywPerIGR1qAl5PgDS\n" +
99 "gMZzSWvMDuT8369m\n" +
100 "-----END PRIVATE KEY-----","PKCS#1","SHA1withRSA",true));
101
102
103 console.log("12345678汉字abcdef,RSAVerifySign_pubK="+this.$RsaVerifySign("12345678汉字abcdef","jpSg6D%2BOE0sSRRKZi7EHngMMwF73hHH4FGQ9YPKdjJzX2pNRYeFgraFYGB4s80tDKv4wkD2P8W06tpWfR4uRfF0Au0nmC1%2FHogi%2FEYTpZNHQlJLMYrLtv6NmQYOidOUWly1iu2NCUuUCFLNNqyARHz%2Bca0e2JZtQmqwBKL8DRIk%3D","-----BEGIN PUBLIC KEY-----\n" +
104 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDooX67neqWx+svZjBqRvO9MHGc\n" +
105 "iqsJnnVJkB9XMLMjoiWWYm9CeCJcUauskwLi0Z1xzNSQZ77yZeqAR7bzOr0o+pEg\n" +
106 "2NEgrqAEXadaCR+wVy03BFVyGxsQ/v+mXGqcnc3JwTLZB6RvqYH/XJX+e8/2qnsB\n" +
107 "AKtNGfqx/slrsoICEwIDAQAB\n" +
108 "-----END PUBLIC KEY-----","PKCS#1","SHA1withRSA",true));

测试结果:

vue 核心加解密工具类 方法的更多相关文章

  1. RSA加解密工具类RSAUtils.java,实现公钥加密私钥解密和私钥解密公钥解密

    package com.geostar.gfstack.cas.util; import org.apache.commons.codec.binary.Base64; import javax.cr ...

  2. Java中的AES加解密工具类:AESUtils

    本人手写已测试,大家可以参考使用 package com.mirana.frame.utils.encrypt; import com.mirana.frame.constants.SysConsta ...

  3. Java中的RSA加解密工具类:RSAUtils

    本人手写已测试,大家可以参考使用 package com.mirana.frame.utils.encrypt; import com.mirana.frame.utils.log.LogUtils; ...

  4. DES加解密工具类

    这两天在跟友商对接接口,在对外暴露接口的时候,因为友商不需要登录即可访问对于系统来说存在安全隐患,所以需要友商在调用接口的时候需要将数据加密,系统解密验证后才执行业务.所有的加密方式并不是万能的,只是 ...

  5. 加解密工具类(含keystore导出pfx)

    java代码如下: package sign; import java.io.FileInputStream; import java.io.FileOutputStream; import java ...

  6. C# 加解密工具类

    using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace Clov ...

  7. Base64加密解密工具类

    使用Apache commons codec类Base64进行加密解密 maven依赖 <dependency> <groupId>commons-codec</grou ...

  8. XJar: Spring-Boot JAR 包加/解密工具,避免源码泄露以及反编译

    XJar: Spring-Boot JAR 包加/解密工具,避免源码泄露以及反编译 <?xml version="1.0" encoding="UTF-8" ...

  9. AES加密、解密工具类

    AES加密.解密工具类代码如下: package com.util; import java.io.IOException; import java.io.UnsupportedEncodingExc ...

随机推荐

  1. 学习java的第八天

    一.今日收获 1.学习完全学习手册上2.3转义字符与2.4运算符两节 二.今日难题 1.没有什么难理解的问题 三.明日目标 1.哔哩哔哩教学视频 2.Java学习手册

  2. 学习java的第五天

    一.今日收获 1.java程序设计完全手册第一章节的小总结 2.完成了部分例题验证解答. 二.今日难题 1.java语言与c++语言的不同点. 2.有例题验证不出来 三.明日目标 1.复习java程序 ...

  3. Learning Spark中文版--第五章--加载保存数据(1)

      开发工程师和数据科学家都会受益于本章的部分内容.工程师可能希望探索更多的输出格式,看看有没有一些适合他们下游用户的格式.数据科学家可能会更关注他们已经使用的数据格式. Motivation   我 ...

  4. 零基础学习java------25--------jdbc

    jdbc开发步骤图 以下要用到的products表 一. JDBC简介 补充    JDBC本质:其实是官方(sun公司)定义的一套操作所有关系型数据库的规则,即接口,各个数据库厂商趋势线这个接口,提 ...

  5. css相关,flex布局全通!

    寻根溯源话布局 一切都始于这样一个问题:怎样通过 CSS 简单而优雅的实现水平.垂直同时居中. 记得刚开始学习 CSS 的时候,看到 float 属性不由得感觉眼前一亮,顺理成章的联想到 Word 文 ...

  6. [PE结构]导入表与IAT表

    导入表的结构导入表的结构 typedef struct _IMAGE_IMPORT_DESCRIPTOR { union { DWORD Characteristics; // 0 for termi ...

  7. oracle 预安装命令

     yum install oracle-rdbms-server-11gR2-preinstall-1.0-6.el6 

  8. 【Python】【Basic】【数据类型】运算符与深浅拷贝

    运算符   1.算数运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 三元运算 三元运算(三目运算),是对简单的条件语句的缩写. # 书写格式 result = 值1 if 条件 ...

  9. 【编程思想】【设计模式】【其他模式】blackboard

    Python版 https://github.com/faif/python-patterns/blob/master/other/blackboard.py #!/usr/bin/env pytho ...

  10. 应用层协议——DHCP

    常见协议分层 网洛层协议:包括:IP协议.ICMP协议.ARP协议.RARP协议. 传输层协议:TCP协议.UDP协议. 应用层协议:FTP.Telnet.SMTP.HTTP.RIP.NFS.DNS ...