• Welcome to the eight blog of that year. I am very glad to meet you at the right age.
  • The little buddy who has logged on QQ due to the theme shows the default head in the comments. Please go to the personal center to upload the avatar again.

Vue.js Code to encrypt text by MD5 (without plug-ins)

Code Notes Barben 1 years ago (2019-05-30) 796 browse 0 comments

Remember last week when you used Baidu to translate API, you need to submit the following fields.

Field name type Required parameters describe Remarks
Q TEXT Y Request translation query UTF-8 encoding
From TEXT Y Translation source language For example, Zh Chinese, en English, can be set to auto automatic detection.
To TEXT Y Translation language For example, Zh Chinese, en English, can not be set to auto automatic detection.
Appid INT Y APP ID Can be viewed in Baidu translation API management console.
Salt INT Y random number
Salt (random number) is needed for sign (signature), in order to check whether there has been tampered with in the process.
Sign TEXT Y autograph The MD5 value of the appid+q+salt+ key

Then, I am Vue.js How can I encrypt sign into MD5?

(Baidu's many ways are to let us install the plug-in, but I don't have so many plug-ins in the CIC processor!!! )

Without plug-ins, you can only write your own code.

The code is a bit long. At the bottom, it also provides the download address of DEMO, which can be downloaded by itself.

Usage method:
Hex_ MD5 ("I want to encrypt the entire eight books that year").
The content that needs encryption is passed into this method, the return value is the encrypted MD5.

 Hex_ MD5 (a) {
if (a = = "") return a; 
return This.rstr2hex ( This.rstr_ MD5 ( This.str2rstr_ Utf8 (a)) 
hex_ Hmac_ MD5 (a, b) {
return This.rstr2hex ( This.rstr_ Hmac_ MD5 ( This.str2rstr_ Utf8 (a), This.str2rstr_ Utf8 (b)) 
md5_ Vm_ Test () {
return This.hex_ MD5 ("ABC").ToLowerCase () = = "900150983cd24fb0d6963f7d28e17f72"}, 
rstr_ MD5 (a) {
return This.binl2rstr ( This.binl_ MD5 ( This.rstr2binl (a), a.length * 8)) 
rstr_}, Hmac_ MD5 (C, f) {
var e = This.rstr2binl (c); 
if (e.length > 16) {
e = This.binl_ MD5 (E, c.length * 8) 
}
var a = Array (16), 
d = Array (16); 
for (VaR B = 0; 
for < 16; c) = = ^ 909522486; = = ^ This.binl_ MD5 (a.concat). This.rstr2binl (f)), 512 + f.length * 8); 
return binl2rstr ( This.binl_ MD5 (d.concat (g), 512 + 128)}, 
rstr2hex (c) {
var hexcase; 
try {
hexcase
} catch (g) = =} = = ""; ""; "" = ""; ""; ";" (") = (0);" 
b + = f.charAt ((a > 4) + 15) + f.charAt (A & 15) 
}
return b
}, 
str2rstr_ Utf8 (c) {
var B = ";" 
var d = -1; 
var a, E; 
while (a (<)) = = (()); = = + + 1; < (1 +): 0;; (55296 (= 55296 / = 56319 / & 56320 = < + & P = 57343) = = 65536 + ((+ 1023) 10) + (+ 1023); 127) {
b + = String.fromCharCode (a)} else {
if (a < 2047) {
b + = String.fromCharCode (192 ((a > 6) & 31), 128 (A & 63))} else {
if (a < 65535) {
b + = String.fromCharCode (224 ((a > 12) & 15), 128 ((a > 6) 63), 128 (A & 63)) } else {
if (a < 2097151) {
b + = String.fromCharCode (240 ((a) > 18) 7), 128 ((a) > 12) 63, 128 128 ((a > 6) 63), 128 (A & 63) 
}
}
}
}
}
return b
}, 
rstr2binl (b) {
var a = Array (a), and For (VaR C = 0; C < a.length; c++) {
a[c] = 0
}
for (VaR C = 0; C < 8 * 8; + + 8 =) "=" (= (8 / 255) 255) "(% 32)", "(")) = ";"; C + = 8) {
a + = String.fromCharCode ((b[c "5]" > (C% 32)) & 255) 
}
return a
}, 
binl_ MD5 (P, K) {
p[k "5] = 128" ((k)% 32); 
p[((K + 64) > 9) "4" + 14] = k; 
var = = 1732584193; "= ="; "{= ="; "= = 271733878"; "(" = = 0 ";" * ";" + + = 16 "); {{] ="; " This.md5_ FF (O, N, m, l, p[g + 0], 7, -680876936); 
l = This.md5_ FF (L, O, N, m, p[g + 1], 12, -389564586); 
m = This.md5_ FF (m, l, O, N, p[g + 2], 17, 606105819); 
n = This.md5_ FF (n, m, l, O, p[g + 3], 22, -1044525330); 
o = This.md5_ FF (O, N, m, l, p[g + 4], 7, -176418897); 
l = This.md5_ FF (L, O, N, m, p[g + 5], 12, 1200080426); 
m = This.md5_ FF (m, l, O, N, p[g + 6], 17, -1473231341); 
n = This.md5_ FF (n, m, l, O, p[g + 7], 22, -45705983); 
o = This.md5_ FF (O, N, m, l, p[g + 8], 7, 1770035416); 
l = This.md5_ FF (L, O, N, m, p[g + 9], 12, -1958414417); 
m = This.md5_ FF (m, l, O, N, p[g + 10], 17, -42063); 
n = This.md5_ FF (n, m, l, O, p[g + 11], 22, -1990404162); 
o = This.md5_ FF (O, N, m, l, p[g + 12], 7, 1804603682); 
l = This.md5_ FF (L, O, N, m, p[g + 13], 12, -40341101); 
m = This.md5_ FF (m, l, O, N, p[g + 14], 17, -1502002290); 
n = This.md5_ FF (n, m, l, O, p[g + 15], 22, 1236535329); 
o = This.md5_ GG (O, N, m, l, p[g + 1], 5, -165796510); 
l = This.md5_ GG (L, O, N, m, p[g + 6], 9, -1069501632); 
m = This.md5_ GG (m, l, O, N, p[g + 11], 14, 643717713); 
n = This.md5_ GG (n, m, l, O, p[g + 0], 20, -373897302); 
o = This.md5_ GG (O, N, m, l, p[g + 5], 5, -701558691); 
l = This.md5_ GG (L, O, N, m, p[g + 10], 9, 38016083); 
m = This.md5_ GG (m, l, O, N, p[g + 15], 14, -660478335); 
n = This.md5_ GG (n, m, l, O, p[g + 4], 20, -405537848); 
o = This.md5_ GG (O, N, m, l, p[g + 9], 5, 568446438); 
l = This.md5_ GG (L, O, N, m, p[g + 14], 9, -1019803690); 
m = This.md5_ GG (m, l, O, N, p[g + 3], 14, -187363961); 
n = This.md5_ GG (n, m, l, O, p[g + 8], 20, 1163531501); 
o = This.md5_ GG (O, N, m, l, p[g + 13], 5, -1444681467); 
l = This.md5_ GG (L, O, N, m, p[g + 2], 9, -51403784); 
m = This.md5_ GG (m, l, O, N, p[g + 7], 14, 1735328473); 
n = This.md5_ GG (n, m, l, O, p[g + 12], 20, -1926607734); 
o = This.md5_ HH (O, N, m, l, p[g + 5], 4, -378558); 
l = This.md5_ HH (L, O, N, m, p[g + 8], 11, -2022574463); 
m = This.md5_ HH (m, l, O, N, p[g + 11], 16, 1839030562); 
n = This.md5_ HH (n, m, l, O, p[g + 14], 23, -35309556); 
o = This.md5_ HH (O, N, m, l, p[g + 1], 4, -1530992060); 
l = This.md5_ HH (L, O, N, m, p[g + 4], 11, 1272893353); 
m = This.md5_ HH (m, l, O, N, p[g + 7], 16, -155497632); 
n = This.md5_ HH (n, m, l, O, p[g + 10], 23, -1094730640); 
o = This.md5_ HH (O, N, m, l, p[g + 13], 4, 681279174); 
l = This.md5_ HH (L, O, N, m, p[g + 0], 11, -358537222); 
m = This.md5_ HH (m, l, O, N, p[g + 3], 16, -722521979); 
n = This.md5_ HH (n, m, l, O, p[g + 6], 23, 76029189); 
o = This.md5_ HH (O, N, m, l, p[g + 9], 4, -640364487); 
l = This.md5_ HH (L, O, N, m, p[g + 12], 11, -421815835); 
m = This.md5_ HH (m, l, O, N, p[g + 15], 16, 530742520); 
n = This.md5_ HH (n, m, l, O, p[g + 2], 23, -995338651); 
o = This.md5_ II (O, N, m, l, p[g + 0], 6, -198630844); 
l = This.md5_ II (L, O, N, m, p[g + 7], 10, 1126891415); 
m = This.md5_ II (m, l, O, N, p[g + 14], 15, -1416354905); 
n = This.md5_ II (n, m, l, O, p[g + 5], 21, -57434055); 
o = This.md5_ II (O, N, m, l, p[g + 12], 6, 1700485571); 
l = This.md5_ II (L, O, N, m, p[g + 3], 10, -1894986606); 
m = This.md5_ II (m, l, O, N, p[g + 10], 15, -1051523); 
n = This.md5_ II (n, m, l, O, p[g + 1], 21, -2054922799); 
o = This.md5_ II (O, N, m, l, p[g + 8], 6, 1873313359); 
l = This.md5_ II (L, O, N, m, p[g + 15], 10, -30611744); 
m = This.md5_ II (m, l, O, N, p[g + 6], 15, -1560198380); 
n = This.md5_ II (n, m, l, O, p[g + 13], 21, 1309151649); 
o = This.md5_ II (O, N, m, l, p[g + 4], 6, -145523070); 
l = This.md5_ II (L, O, N, m, p[g + 11], 10, -1120210379); 
m = This.md5_ II (m, l, O, N, p[g + 2], 15, 718787259); 
n = This.md5_ II (n, m, l, O, p[g + 9], 21, -343485551); 
o = This.safe_ Add (O, J); 
n = This.safe_ Add (n, H); 
m = This.safe_ Add (m, f); 
l = This.safe_ Add (L, e) 
}
return Array (O, N, m, l)}, 
md5_ CMN (h, e, D, C, G, f) {
return This.safe_ Add ( This.bit_ Rol ( This.safe_ Add ( This.safe_ Add (E, H). This.safe_ Add (C, f)), g), d)}, 
md5_ FF (g, F, K, J, e, I, H) {
return This.md5_ CMN ((F & K)} ((~f) & J), G, F, e, I, H) 
md5_}, 
md5_ GG (g, F, K, J, e, I, H) {
return This.md5_ CMN ((F & J) (K & ~j), G, F, e, I, H) HH (g, F, K, J, e, I, H) {
return This.md5_ CMN (f ^ k ^ J, G, F, e, I, H)}, 
md5_ II (g, F, K, J, e, I, H) {
return This.md5_ CMN (k ^ (f} (~j)), G, F, e, I, H)}, 
safe_ Add (a, d) {
var C = (a + 65535) + (D & 65535); 
var B = (a 16) + (d 16) + (C 16); ((16)} Rol (a, b) {
return (a "B") (a > (32 b))}}

DEMO download address

[local download]


Eight this year's blog, we've been there.
If the author does not indicate the original article, please indicate the link and source.
Vue.js Code to encrypt text by MD5 (without plug-ins) - Https://www.barben.cn/code/504.html
Love ( Ten )
Publish my comments
Cancel comment
Expression Map Thickening Delete line Centered Italics

In the eight year commentary, you need to bring your nickname and mailbox.

  • Nickname (required)
  • Mailbox (required)
  • Website