沙钢智慧能源系统前端代码
houzhongjian
2024-10-09 314507f8ddadd9c66e98d260c3b2a5dad1a04015
提交 | 用户 | 时间
314507 1 import { JSEncrypt } from 'jsencrypt'
H 2
3 // 密钥对生成 http://web.chacuo.net/netrsakeypair
4
5 const publicKey =
6   'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
7   'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
8
9 const privateKey =
10   'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
11   '7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
12   'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
13   'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
14   'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
15   'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
16   'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
17   'UP8iWi1Qw0Y='
18
19 // 加密
20 export const encrypt = (txt: string) => {
21   const encryptor = new JSEncrypt()
22   encryptor.setPublicKey(publicKey) // 设置公钥
23   return encryptor.encrypt(txt) // 对数据进行加密
24 }
25
26 // 解密
27 export const decrypt = (txt: string) => {
28   const encryptor = new JSEncrypt()
29   encryptor.setPrivateKey(privateKey) // 设置私钥
30   return encryptor.decrypt(txt) // 对数据进行解密
31 }