mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Add crypto functions
This commit is contained in:
parent
cb258577ea
commit
89e612900c
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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user