CryptoJS值JavaScript加密算法,sha, md5, rc4, base64, aes

CryptoJS-为JavaScript提供了各种各样的加密算法

- 摘要算法

- MD5/HmacMD5

- SHA1/HmacSHA1

- SHA3/HmacSHA3

- SHA224/HmacSHA224

- SHA256/HmacSHA256

- SHA384/HmacSHA384

- SHA512/HmacSHA512

- PBKDF2

- EvpKDF

- RIPEMD160

- 编码算法

- Base64

- 加密算法

- RC4

- RabbitLegacy

- Rabbit

- AES

- DES

支持的算法包括:
MD5,SHA-1,SHA-256,AES,Rabbit,MARC4,HMAC,HMAC-MD5,HMAC-SHA1,HMAC-SHA256,PBKDF2

1.
2.
var CryptoJS = require( "cryptojs" );
CryptoJS.require.Hmac(); //如果需要计算HMAC值,必须引用Hmac模块。

TOP摘要算法

TOPMD5/HmacMD5

用框架内置的MD5同样的结果。

1.
2.
3.
CryptoJS.require.MD5();
F .echo(CryptoJS.MD5( "anlige" ), true );
F .echo(CryptoJS.HmacMD5( "anlige" , "lilith" ), true );

TOPSHA1/HmacSHA1

用框架内置的SHA1同样的结果。

1.
2.
3.
CryptoJS.require.SHA1();
F .echo(CryptoJS.SHA1( "anlige" ), true );
F .echo(CryptoJS.HmacSHA1( "anlige" , "lilith" ), true );

TOPSHA3/HmacSHA3

1.
2.
3.
CryptoJS.require( "sha3" , "x64-core" ); //需要x64-core模块支持
F .echo(CryptoJS.SHA3( "anlige" ), true );
F .echo(CryptoJS.HmacSHA3( "anlige" , "lilith" ), true );

TOPSHA224/HmacSHA224

1.
2.
3.
CryptoJS.require( "sha224" , "sha256" ); //需要sha256模块支持
F .echo(CryptoJS.SHA224( "anlige" ), true );
F .echo(CryptoJS.HmacSHA224( "anlige" , "lilith" ), true );

TOPSHA256/HmacSHA256

1.
2.
3.
CryptoJS.require( "sha256" );
F .echo(CryptoJS.SHA256( "anlige" ), true );
F .echo(CryptoJS.HmacSHA256( "anlige" , "lilith" ), true );

TOPSHA384/HmacSHA384

1.
2.
3.
CryptoJS.require( "sha384" , "x64-core" , "sha512" );
F .echo(CryptoJS.SHA384( "anlige" ), true );
F .echo(CryptoJS.HmacSHA384( "anlige" , "lilith" ), true );

TOPSHA512/HmacSHA512

1.
2.
3.
CryptoJS.require( "sha512" , "x64-core" );
F .echo(CryptoJS.SHA512( "anlige" ), true );
F .echo(CryptoJS.HmacSHA512( "anlige" , "lilith" ), true );

TOPPBKDF2

1.
2.
3.
CryptoJS.require.PBKDF2();
var result = CryptoJS.PBKDF2( "anlige" , "lilith" , {keySize: 128 / 32 ,iterations: 10 });
F .echo(result);

TOPEvpKDF

1.
2.
3.
CryptoJS.require.EvpKDF();
var result = CryptoJS.EvpKDF( "anlige" , "lilith" , {keySize: 128 / 32 ,iterations: 10 });
F .echo(result);

TOPRIPEMD160

1.
2.
3.
CryptoJS.require( "ripemd160" );
var result = CryptoJS.RIPEMD160( "anlige" );
F .echo(result);

TOP编码算法

TOPBase64

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
CryptoJS.require( "enc-base64" );
//编码
var src = CryptoJS.enc.Utf8.parse( "anlige" );
var base64string = CryptoJS.enc.Base64.stringify(src);
F .echo(base64string.toString());
 
//解码
var base64string = CryptoJS.enc.Base64.parse( "YW5saWdl" );
F .echo(CryptoJS.enc.Utf8.stringify(base64string));
}

TOP加密算法

TOPRC4

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
CryptoJS.require.RC4().Format.Hex();
var key = CryptoJS.enc.Utf8.parse( "password" );
//加密
var srcs = CryptoJS.enc.Utf8.parse( "anlige" );
F .echo(CryptoJS.RC4.encrypt(srcs, key).toString(CryptoJS.format.Hex));
//解密
var srcs = CryptoJS.enc.Hex.parse( "9e9b54672b5b" );
var decryptdata = CryptoJS.RC4.decrypt(
     CryptoJS.lib.CipherParams.create({ ciphertext:srcs}),
     key
);
//解密
F .echo(decryptdata.toString(CryptoJS.enc.Utf8));

TOPRabbitLegacy

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
CryptoJS.require.Padding().Mode();
CryptoJS.require.RabbitLegacy().Format.Hex();
var key = CryptoJS.enc.Utf8.parse( "f2c20576f726c641" );
var iv  = CryptoJS.enc.Utf8.parse( "6f726c64f2c20572" );
var cfg={
     iv: iv,
     mode:CryptoJS.mode.CFB,
     padding:CryptoJS.pad.Pkcs7,
     format:CryptoJS.format.Hex
};
//加密
var srcs = CryptoJS.enc.Utf8.parse( "anlige测试" );
F .echo(CryptoJS.RabbitLegacy.encrypt(srcs, key, cfg).toString(), true );
//解密
var srcs = CryptoJS.enc.Hex.parse( "71d7f64fb887f384057c4798" );
var decryptdata = CryptoJS.RabbitLegacy.decrypt(
     CryptoJS.lib.CipherParams.create({ ciphertext:srcs}),
     key,
     cfg
);
F .echo(decryptdata.toString(CryptoJS.enc.Utf8));

TOPRabbit

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
CryptoJS.require.Padding().Mode();
CryptoJS.require.Rabbit().Format.Hex();
CryptoJS.require.RabbitLegacy();
var key = CryptoJS.enc.Utf8.parse( "f2c20576f726c641" );
var iv  = CryptoJS.enc.Utf8.parse( "6f726c64f2c20572" );
var cfg={
     iv: iv,
     mode:CryptoJS.mode.CFB,
     padding:CryptoJS.pad.Pkcs7,
     format:CryptoJS.format.Hex
};
//加密
var srcs = CryptoJS.enc.Utf8.parse( "anlige测试" );
F .echo(CryptoJS.Rabbit.encrypt(srcs, key, cfg).toString(), true );
//解密
var srcs = CryptoJS.enc.Hex.parse( "fe82ea8e0d3582e60871c394" );
var decryptdata = CryptoJS.RabbitLegacy.decrypt(
     CryptoJS.lib.CipherParams.create({ ciphertext:srcs}),
     key,
     cfg
);
F .echo(decryptdata.toString(CryptoJS.enc.Utf8));

TOPAES

mode支持:CBC,CFB,CTR,CTRGladman,ECB,OFB
padding支持:ZeroPadding,NoPadding,AnsiX923,Iso10126,Iso97971,Pkcs7

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
CryptoJS.require.Padding().Mode();
CryptoJS.require.AES().Format.Hex();
var key = CryptoJS.enc.Utf8.parse( "f2c20576f726c641" );
var iv  = CryptoJS.enc.Utf8.parse( "6f726c64f2c20572" );
var cfg={
     iv: iv,
     mode:CryptoJS.mode.CBC,
     padding:CryptoJS.pad.Pkcs7,
     format:CryptoJS.format.Hex
};
//加密
var srcs = CryptoJS.enc.Utf8.parse( "anlige测试" );
F .echo(CryptoJS.AES.encrypt(srcs, key, cfg).toString(), true );
//解密
var srcs = CryptoJS.enc.Hex.parse( "2783726e20d0d334520cbbbb9cd95d9b" );
var decryptdata = CryptoJS.AES.decrypt(
     CryptoJS.lib.CipherParams.create({ ciphertext:srcs}),
     key,
     cfg
);
F .echo(decryptdata.toString(CryptoJS.enc.Utf8));

TOPDES

mode支持:CBC,CFB,CTR,CTRGladman,ECB,OFB
padding支持:ZeroPadding,NoPadding,AnsiX923,Iso10126,Iso97971,Pkcs7

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
CryptoJS.require.Padding().Mode();
CryptoJS.require.DES().Format.Hex();
var key = CryptoJS.enc.Utf8.parse( "f2c20576f726c641" );
var iv  = CryptoJS.enc.Utf8.parse( "6f726c64f2c20572" );
var cfg={
     iv: iv,
     mode:CryptoJS.mode.CFB,
     padding:CryptoJS.pad.Pkcs7,
     format:CryptoJS.format.Hex
};
//加密
var srcs = CryptoJS.enc.Utf8.parse( "anlige测试" );
F .echo(CryptoJS.DES.encrypt(srcs, key, cfg).toString(), true );
//解密
var srcs = CryptoJS.enc.Hex.parse( "9e418a0562e550d0ff42dccfeb3ece64" );
var decryptdata = CryptoJS.DES.decrypt(
     CryptoJS.lib.CipherParams.create({ ciphertext:srcs}),
     key,
     cfg
);
F .echo(decryptdata.toString(CryptoJS.enc.Utf8));

你可能感兴趣的:(CryptoJS值JavaScript加密算法,sha, md5, rc4, base64, aes)