1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 21:39:22 +00:00

Add crypto functions

This commit is contained in:
Pierre HUBERT 2019-11-23 11:26:05 +01:00
parent cb258577ea
commit 89e612900c

30
src/utils/CryptUtils.ts Normal file
View 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();
}