本文整理匯總了TypeScript中crypto.createCipher函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createCipher函數的具體用法?TypeScript createCipher怎麽用?TypeScript createCipher使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了createCipher函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: encrypt
public encrypt(file: string, algorithm: string, password: string): void {
let cipher = createCipher(algorithm, password),
cipherName = createCipher(algorithm, password),
encryptedFileName,
decrypted,
encrypted,
pathArray,
fileName,
path;
pathArray = file.split('/');
fileName = pathArray.pop();
path = pathArray.join('/') + '/encrypted';
mkdir(path);
encryptedFileName = cipherName.update(fileName, 'utf8', 'hex');
encryptedFileName += cipherName.final('hex');
path += '/' + encryptedFileName;
decrypted = createReadStream(file);
encrypted = createWriteStream(path);
decrypted
.pipe(cipher)
.pipe(encrypted);
}
示例2: encrypt
export function encrypt(input:string, secret:string, callback: (result: string) => void) : void {
if(input) {
if(secret) {
try {
var cipher = crypto.createCipher(algorithm, secret)
var result = cipher.update(input, 'utf8', 'hex') + cipher.final('hex')
callback(result)
} catch( e) {
callback(null)
}
return
}
}
callback(null)
}
示例3: encrypt
encrypt(value) {
let cipher = crypto.createCipher('aes-256-ctr', this.secretKey.value);
let encrypted = cipher.update(value, 'utf8', 'binary');
encrypted += cipher.final('binary');
let hexVal = new Buffer(encrypted, 'binary');
return hexVal.toString('base64');
}
示例4: encrypt
export function encrypt(text: string, key: string): string {
let cryptoKey = !key ? localKey : key;
const cipher = crypto.createCipher('aes-256-cbc',cryptoKey);
let encipheredContent: string = cipher.update(text,'utf8','hex');
encipheredContent += cipher.final('hex');
return encipheredContent;
}
示例5: encrypt
export function encrypt(text) {
const cipher = crypto.createCipher('aes-256-cbc', process.env.APP_KEY);
let crypted = cipher.update(text, 'utf8', 'base64');
crypted += cipher.final('base64');
return crypted;
}
示例6:
export const cryptoPassword = (password: string) => {
// 先 md5 不可逆加密
const md5 = crypto.createHash('md5')
md5.update(password, 'utf8')
const md5Str = md5.digest('hex')
// 再 aes 對稱加密(密匙私有!)
const aes = crypto.createCipher('aes-256-cbc', process.env.PASSWORD_SECRET)
return aes.update(md5Str, 'utf8', 'hex') + aes.final('hex')
}
示例7: 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);
}
示例8: 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.send(404).send({ Error: 'No such file ID' });
}
const cipher = crypto.createCipher('aes256', new Buffer(APP_CONFIG.storage_key, 'base64'));
let pl = req.pipe(zlib.createGzip()).pipe(cipher);
store.store(fileid, pl, function (perr) {
if (perr) {
return res.status(500).send({ Error: perr });
}
return res.send({ Success: true });
});
});
示例9: 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);
}
示例10: getEncAse192
export function getEncAse192(str, secret = 'lqbw') {
const cipher = crypto.createCipher('aes192', secret);
let enc = cipher.update(str, 'utf8', 'hex');
enc += cipher.final('hex');
return enc;
}
示例11: encrypt
//
// Encrypt the password hash using a secret from our config file.
// We do this so if an attacker acquired the database (e.g. through
// SQL injection) then the password hashes will be unreadable.
//
function encrypt(input: string): string {
const cipher = crypto.createCipher('aes256', config.security.passwordSecret);
let output = cipher.update(input, 'ascii', 'base64');
output += cipher.final('base64');
return output;
}
示例12: encrypt
export function encrypt(text:string) : string {
var cipher = crypto.createCipher(algorithm,config.secret);
var crypted = cipher.update(text,'utf8','hex');
crypted += cipher.final('hex');
return crypted;
}
示例13: encrypt
/**
* Encrypt
* @param {string} str
* @param {string} password
* @param {string} algo
* @return {string}
*/
public static encrypt(str: string, password: string, algo: string): string {
let cipher = crypto.createCipher(algo, password);
let crypted = cipher.update(str, 'utf8', 'hex');
crypted += cipher.final('hex');
return crypted;
}
示例14: stringEncrypt
export function stringEncrypt(text: string, pass: string): string {
let cipher = crypto.createCipher('aes-256-ctr', pass);
let crypted = cipher.update(text, 'utf8', 'hex');
crypted += cipher.final('hex');
return crypted;
}
示例15: encrypt
export function encrypt(text: string, key: string) {
return evaluate('utf8', 'hex', text, createCipher(ALGORITHM, key));
}