本文整理匯總了TypeScript中crypto.createDecipher函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createDecipher函數的具體用法?TypeScript createDecipher怎麽用?TypeScript createDecipher使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了createDecipher函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: decrypt
public decrypt(file: string, algorithm: string, password: string): void {
let decipher = createDecipher(algorithm, password),
decipherName = createDecipher(algorithm, password),
decryptedFileName,
encrypted,
decrypted,
pathArray,
fileName,
path;
pathArray = file.split('/');
fileName = pathArray.pop();
path = pathArray.join('/');
decryptedFileName = decipherName.update(fileName, 'hex', 'utf8');
decryptedFileName += decipherName.final('utf8');
path += '/' + decryptedFileName;
encrypted = createReadStream(file);
decrypted = createWriteStream(path);
encrypted
.pipe(decipher)
.pipe(decrypted);
}
示例2: decrypt
export function decrypt(text) {
const cipher = crypto.createDecipher('aes-256-cbc', process.env.APP_KEY);
let crypted = cipher.update(text, 'base64', 'utf8');
crypted += cipher.final('utf8');
return crypted;
}
示例3: decrypt
export function decrypt(text: string, key: string): string {
let cryptoKey = !key ? localKey : key;
const cipher = crypto.createDecipher('aes-256-cbc',cryptoKey);
var decipheredPlaintext = cipher.update(text,'hex','utf8');
decipheredPlaintext += cipher.final('utf8');
return decipheredPlaintext;
}
示例4: decrypt
export function decrypt(input:string, secret:string, callback: (result: string) => void) : void {
if(input) {
if(secret) {
try {
var decipher = crypto.createDecipher(algorithm, secret)
var result = decipher.update(input, 'hex', 'utf8') + decipher.final('utf8')
callback(result)
} catch( e) {
callback(null)
}
return
}
}
callback(null)
}
示例5: Buffer
conn.query(q, args, (qerr, results) => {
conn.release();
if (qerr) {
console.log('Error validating file id', qerr);
return res.status(500).send({ Error: 'Internal Server Error' });
}
if (results.length < 1) {
return res.status(404).send({ Error: 'No such file ID' });
}
const decipher = crypto.createDecipher('aes256', new Buffer(APP_CONFIG.storage_key, 'base64'));
store.get(fileid).pipe(decipher).pipe(zlib.createGunzip()).pipe(res).once('close', () => res.end());
});
示例6: crypto_cipher_decipher_string_test
function crypto_cipher_decipher_string_test() {
var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]);
var clearText:string = "This is the clear text.";
var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key);
var cipherText:string = cipher.update(clearText, "utf8", "hex");
cipherText += cipher.final("hex");
var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key);
var clearText2:string = decipher.update(cipherText, "hex", "utf8");
clearText2 += decipher.final("utf8");
assert.equal(clearText2, clearText);
}
示例7: _readTaskLibSecrets
private static _readTaskLibSecrets(lookupKey: string): string {
// the lookupKey should has following format
// base64encoded<keyFilePath>:base64encoded<encryptedContent>
if (lookupKey && lookupKey.indexOf(':') > 0) {
let lookupInfo: string[] = lookupKey.split(':', 2);
// file contains encryption key
let keyFile = new Buffer(lookupInfo[0], 'base64').toString('utf8');
let encryptKey = new Buffer(fs.readFileSync(keyFile, 'utf8'), 'base64');
let encryptedContent: string = new Buffer(lookupInfo[1], 'base64').toString('utf8');
let decipher = crypto.createDecipher("aes-256-ctr", encryptKey)
let decryptedContent = decipher.update(encryptedContent, 'hex', 'utf8')
decryptedContent += decipher.final('utf8');
return decryptedContent;
}
}
示例8: crypto_cipher_decipher_buffer_test
function crypto_cipher_decipher_buffer_test() {
var key:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7]);
var clearText:Buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4]);
var cipher:crypto.Cipher = crypto.createCipher("aes-128-ecb", key);
var cipherBuffers:Buffer[] = [];
cipherBuffers.push(cipher.update(clearText));
cipherBuffers.push(cipher.final());
var cipherText:Buffer = Buffer.concat(cipherBuffers);
var decipher:crypto.Decipher = crypto.createDecipher("aes-128-ecb", key);
var decipherBuffers:Buffer[] = [];
decipherBuffers.push(decipher.update(cipherText));
decipherBuffers.push(decipher.final());
var clearText2:Buffer = Buffer.concat(decipherBuffers);
assert.deepEqual(clearText2, clearText);
}
示例9: decrypt
function decrypt(input: string): string {
const decipher = crypto.createDecipher('aes256', config.security.passwordSecret);
let output = decipher.update(input, 'base64', 'ascii');
output += decipher.final('ascii');
return output;
}
示例10: stringDecrypt
export function stringDecrypt(text: string, pass: string): string {
let decipher = crypto.createDecipher('aes-256-ctr', pass);
let dec = decipher.update(text, 'hex', 'utf8');
dec += decipher.final('utf8');
return dec;
}