crypto-js html
时间: 2023-10-29 15:00:42 浏览: 111
Crypto-js is a JavaScript library that provides various cryptographic algorithms. To use Crypto-js in an HTML file, you need to include the library in your project and then reference it in your HTML file.
First, you can download the Crypto-js library from the official website or include it using a package manager like npm or yarn.
If you are downloading it manually, you can include the library by adding the following script tag to your HTML file:
```html
<script src="path/to/crypto-js.js"></script>
```
Replace `path/to/crypto-js.js` with the actual path to the Crypto-js library file.
Once you have included the library, you can start using its functionalities in your JavaScript code.
Here's an example of how you can use Crypto-js to encrypt and decrypt a message using the AES algorithm:
```html
<!DOCTYPE html>
<html>
<head>
<title>Crypto-js Example</title>
<script src="path/to/crypto-js.js"></script>
<script>
// Example encryption and decryption
var plaintext = "Hello, World!";
var password = "secret passphrase";
// Encrypt
var ciphertext = CryptoJS.AES.encrypt(plaintext, password).toString();
// Decrypt
var bytes = CryptoJS.AES.decrypt(ciphertext, password);
var decryptedText = bytes.toString(CryptoJS.enc.Utf8);
console.log("Plaintext: " + plaintext);
console.log("Ciphertext: " + ciphertext);
console.log("Decrypted Text: " + decryptedText);
</script>
</head>
<body>
</body>
</html>
```
Remember to replace `path/to/crypto-js.js` with the actual path to the Crypto-js library file.
This is just a basic example, and Crypto-js provides many other cryptographic algorithms and functionalities that you can explore in their documentation.
阅读全文