You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			19 lines
		
	
	
		
			414 B
		
	
	
	
		
			TypeScript
		
	
		
		
			
		
	
	
			19 lines
		
	
	
		
			414 B
		
	
	
	
		
			TypeScript
		
	
| 
											3 years ago
										 | import CryptoJS from 'crypto-js' | ||
|  | 
 | ||
|  | const CryptoSecret = '__CRYPTO_SECRET__' | ||
|  | 
 | ||
|  | export function enCrypto(data: any) { | ||
|  |   const str = JSON.stringify(data) | ||
|  |   return CryptoJS.AES.encrypt(str, CryptoSecret).toString() | ||
|  | } | ||
|  | 
 | ||
|  | export function deCrypto(data: string) { | ||
|  |   const bytes = CryptoJS.AES.decrypt(data, CryptoSecret) | ||
|  |   const str = bytes.toString(CryptoJS.enc.Utf8) | ||
|  | 
 | ||
|  |   if (str) | ||
|  |     return JSON.parse(str) | ||
|  | 
 | ||
|  |   return null | ||
|  | } |