From e1699c4851f6ca397cd0ad1ff63f32c737654836 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Wed, 02 Apr 2025 19:14:54 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
src/utils/crypto.js | 170 ++++++++++++++++++++++++++++----------------------------
1 files changed, 85 insertions(+), 85 deletions(-)
diff --git a/src/utils/crypto.js b/src/utils/crypto.js
index 4bbd03a..8293bbf 100644
--- a/src/utils/crypto.js
+++ b/src/utils/crypto.js
@@ -1,94 +1,94 @@
-import CryptoJS from 'crypto-js';
+import CryptoJS from 'crypto-js'
export default class crypto {
- /**
- * token加密key 使用@org.springblade.test.CryptoKeyGenerator获取,需和后端配置保持一致
- * @type {string}
- */
- static cryptoKey = '请配置cryptoKey';
- /**
- * 报文加密key 使用@org.springblade.test.CryptoKeyGenerator获取,需和后端配置保持一致
- * @type {string}
- */
- static aesKey = '请配置aesKey';
- /**
- * 报文加密key 使用@org.springblade.test.CryptoKeyGenerator获取,需和后端配置保持一致
- * @type {string}
- */
- static desKey = '请配置desKey';
+ /**
+ * token加密key 使用@org.springblade.test.CryptoKeyGenerator获取,需和后端配置保持一致
+ * @type {string}
+ */
+ static cryptoKey = '请配置cryptoKey'
+ /**
+ * 报文加密key 使用@org.springblade.test.CryptoKeyGenerator获取,需和后端配置保持一致
+ * @type {string}
+ */
+ static aesKey = '请配置aesKey'
+ /**
+ * 报文加密key 使用@org.springblade.test.CryptoKeyGenerator获取,需和后端配置保持一致
+ * @type {string}
+ */
+ static desKey = '请配置desKey'
- /**
- * aes 加密方法
- * @param data
- * @returns {*}
- */
- static encrypt(data) {
- return this.encryptAES(data, this.aesKey);
- }
+ /**
+ * aes 加密方法
+ * @param data
+ * @returns {*}
+ */
+ static encrypt(data) {
+ return this.encryptAES(data, this.aesKey)
+ }
- /**
- * aes 解密方法
- * @param data
- * @returns {*}
- */
- static decrypt(data) {
- return this.decryptAES(data, this.aesKey);
- }
+ /**
+ * aes 解密方法
+ * @param data
+ * @returns {*}
+ */
+ static decrypt(data) {
+ return this.decryptAES(data, this.aesKey)
+ }
- /**
- * aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
- */
- static encryptAES(data, key) {
- const dataBytes = CryptoJS.enc.Utf8.parse(data);
- const keyBytes = CryptoJS.enc.Utf8.parse(key);
- const encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, {
- iv: keyBytes,
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.Pkcs7,
- });
- return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
- }
+ /**
+ * aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
+ */
+ static encryptAES(data, key) {
+ const dataBytes = CryptoJS.enc.Utf8.parse(data)
+ const keyBytes = CryptoJS.enc.Utf8.parse(key)
+ const encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, {
+ iv: keyBytes,
+ mode: CryptoJS.mode.CBC,
+ padding: CryptoJS.pad.Pkcs7,
+ })
+ return CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
+ }
- /**
- * aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
- */
- static decryptAES(data, key) {
- const keyBytes = CryptoJS.enc.Utf8.parse(key);
- const decrypted = CryptoJS.AES.decrypt(data, keyBytes, {
- iv: keyBytes,
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.Pkcs7,
- });
- return CryptoJS.enc.Utf8.stringify(decrypted);
- }
+ /**
+ * aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
+ */
+ static decryptAES(data, key) {
+ const keyBytes = CryptoJS.enc.Utf8.parse(key)
+ const decrypted = CryptoJS.AES.decrypt(data, keyBytes, {
+ iv: keyBytes,
+ mode: CryptoJS.mode.CBC,
+ padding: CryptoJS.pad.Pkcs7,
+ })
+ return CryptoJS.enc.Utf8.stringify(decrypted)
+ }
- /**
- * des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
- */
- static encryptDES(data, key) {
- const keyHex = CryptoJS.enc.Utf8.parse(key);
- const encrypted = CryptoJS.DES.encrypt(data, keyHex, {
- mode: CryptoJS.mode.ECB,
- padding: CryptoJS.pad.Pkcs7,
- });
- return encrypted.toString();
- }
+ /**
+ * des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
+ */
+ static encryptDES(data, key) {
+ const keyHex = CryptoJS.enc.Utf8.parse(key)
+ const encrypted = CryptoJS.DES.encrypt(data, keyHex, {
+ mode: CryptoJS.mode.ECB,
+ padding: CryptoJS.pad.Pkcs7,
+ })
+ return encrypted.toString()
+ }
- /**
- * des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
- */
- static decryptDES(data, key) {
- const keyHex = CryptoJS.enc.Utf8.parse(key);
- const decrypted = CryptoJS.DES.decrypt(
- {
- ciphertext: CryptoJS.enc.Base64.parse(data),
- },
- keyHex,
- {
- mode: CryptoJS.mode.ECB,
- padding: CryptoJS.pad.Pkcs7,
- }
- );
- return decrypted.toString(CryptoJS.enc.Utf8);
- }
+ /**
+ * des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
+ */
+ static decryptDES(data, key) {
+ const keyHex = CryptoJS.enc.Utf8.parse(key)
+ const decrypted = CryptoJS.DES.decrypt(
+ {
+ ciphertext: CryptoJS.enc.Base64.parse(data),
+ },
+ keyHex,
+ {
+ mode: CryptoJS.mode.ECB,
+ padding: CryptoJS.pad.Pkcs7,
+ }
+ )
+ return decrypted.toString(CryptoJS.enc.Utf8)
+ }
}
--
Gitblit v1.9.3