24 lines
		
	
	
		
			618 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			618 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import CryptoJs from  "crypto-js";
 | |
| 
 | |
| /**
 | |
|  * 密码加密工具
 | |
|  * @param params
 | |
|  * @param c 加载尝试计数器
 | |
|  * @returns {string}
 | |
|  */
 | |
| export const $encryption = (params, c = 0) => {
 | |
|   if (CryptoJs) {
 | |
|     const key = "thanks,villcloud"
 | |
|     let iv = CryptoJs.enc.Latin1.parse(key)
 | |
|     let encrypted = CryptoJs.AES.encrypt(params.password, iv, {
 | |
|       iv,
 | |
|       mode: CryptoJs.mode.CBC,
 | |
|       padding: CryptoJs.pad.ZeroPadding
 | |
|     })
 | |
|     return encrypted.toString()
 | |
|   } else if (c < 10) {
 | |
|     setTimeout(() => $encryption(params, ++c), 200)
 | |
|   } else console.error("无法加载CryptoJs")
 | |
| }
 | |
| export default $encryption
 |