JavaScript 加密库Crypto-JS

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liuruiqun/article/details/52275591

CryptoJS


CryptoJS是一个纯javascript写的加密类库,使用起来简单方便。目前已支持的算法包括:

  • MD5
  • SHA-1
  • SHA-256
  • AES
  • Rabbit
  • MARC4
  • HMAC
    • HMAC-MD5
    • HMAC-SHA1
    • HMAC-SHA256
  • PBKDF2

具体介绍和下载链接地址:https://code.google.com/archive/p/crypto-js/


CryptoJS库的使用


CryptoJS的使用很方便,只需引用相关的库文件即可。


MD5


MD5 is a widely used hash function. It's been used in a variety of security applications and is also commonly used to check the integrity of files. Though, MD5 is not collision resistant, and it isn't suitable for applications like SSL certificates or digital signatures that rely on this property.

```
var hash = CryptoJS.MD5("Message");

```

SHA-1


The SHA hash functions were designed by the National Security Agency (NSA). SHA-1 is the most established of the existing SHA hash functions, and it's used in a variety of security applications and protocols. Though, SHA-1's collision resistance has been weakening as new attacks are discovered or improved.

```
var hash = CryptoJS.SHA1("Message");

```

SHA-2


SHA-256 is one of the four variants in the SHA-2 set. It isn't as widely used as SHA-1, though it appears to provide much better security.

```
var hash = CryptoJS.SHA256("Message");

```

SHA-512 is largely identical to SHA-256 but operates on 64-bit words rather than 32.

```
var hash = CryptoJS.SHA512("Message");

```



猜你喜欢

转载自blog.csdn.net/liuruiqun/article/details/52275591