标签:xtend ring uppercase def const ted fun ram UNC
import React, { Component } from ‘react‘;
import CryptoJS from ‘crypto-js/crypto-js‘
import { Button } from ‘antd‘;
class Encryption extends Component {
constructor(){
super();
this.state={
value2:‘qqqqqqqqqqqq‘,
encryptioned:‘‘,
Decrypted:‘‘
}
}
componentDidMount(){
}
///对文件进行加密
encryption = (e,dataw)=>{
debugger
let data = this.state.value2;
let srcs = CryptoJS.enc.Utf8.parse(data);
let key = CryptoJS.enc.Utf8.parse(‘1111111111111111‘);//Latin1 w8m31+Yy/Nw6thPsMpO5fg==
let encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
this.setState({encryptioned: encrypted.toString()});
};
///对文件进行解密
Decrypt=(e,data)=>{
let word = this.state.encryptioned;///o7H8uIM2O5qv65l2
let key = CryptoJS.enc.Utf8.parse(‘1111111111111111‘);//Latin1 w8m31+Yy/Nw6thPsMpO5fg==
let decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
this.setState({Decrypted:CryptoJS.enc.Utf8.stringify(decrypt).toString()});
};
render() {
return(
<div>
<p><input value={this.state.value2} type="text"/></p>
<Button type="primary" onClick={this.encryption.bind(this)}>请输入要加密的内容</Button>
<br/>
<h2>
加密之后的内容:<span>{this.state.encryptioned}</span>
</h2>
<Button type="primary" onClick={this.Decrypt.bind(this)}>对加密文件进行解密</Button>
<br/>
<h2>
解密之后的内容:<span>{this.state.Decrypted}</span>
</h2>
</div>
)
}
}
export default Encryption;
这里的密钥是由十六位十六进制数作为密钥组成
//十六位十六进制数作为密钥偏移量
标签:xtend ring uppercase def const ted fun ram UNC
原文地址:https://www.cnblogs.com/boonook/p/9721470.html