mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 11:34:04 +00:00 
			
		
		
		
	Add crypto functions
This commit is contained in:
		
							
								
								
									
										30
									
								
								src/utils/CryptUtils.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/utils/CryptUtils.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Cryptographic utilities
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @author Pierre HUBERT
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import * as crypto from 'crypto';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { execSync } from 'child_process';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Generate sha1-encoded string
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param str The string to encode
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function sha1(str : string) : string {
 | 
				
			||||||
 | 
						const shasum = crypto.createHash("sha1");
 | 
				
			||||||
 | 
						shasum.update(str);
 | 
				
			||||||
 | 
						return shasum.digest("hex");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Interface with PHP crypt function
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param str The string to encrypt
 | 
				
			||||||
 | 
					 * @param salt Salt to use
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function crypt(str : string, salt: string) : string {
 | 
				
			||||||
 | 
						return execSync("/usr/bin/php -r \"echo crypt(\'"+str+"\', \'"+salt+"\');\"").toString();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user