diff --git a/src/utils/CryptUtils.ts b/src/utils/CryptUtils.ts new file mode 100644 index 0000000..8922dc4 --- /dev/null +++ b/src/utils/CryptUtils.ts @@ -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(); +} \ No newline at end of file