當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript crypto.createCipher函數代碼示例

本文整理匯總了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);
  }
開發者ID:robwormald,項目名稱:xnb-crypto-ng2,代碼行數:27,代碼來源:cryptography.service.ts

示例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)
    }
開發者ID:sinclairzx81,項目名稱:taxman,代碼行數:25,代碼來源:secret.ts

示例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');
 }
開發者ID:workfel,項目名稱:vulcain-corejs,代碼行數:7,代碼來源:crypto.ts

示例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;
 }
開發者ID:jgkim7,項目名稱:blog,代碼行數:7,代碼來源:crypto.ts

示例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;
}
開發者ID:Poniverse,項目名稱:LunaTube,代碼行數:7,代碼來源:AuthHelpers.ts

示例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')
}
開發者ID:linkFly6,項目名稱:Said,代碼行數:9,代碼來源:admin-service.ts

示例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);
}
開發者ID:Cyr1l,項目名稱:DefinitelyTyped,代碼行數:13,代碼來源:node-tests.ts

示例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 });
     });
 });
開發者ID:TetuSecurity,項目名稱:Crypt,代碼行數:18,代碼來源:files.ts

示例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);
}
開發者ID:Cyr1l,項目名稱:DefinitelyTyped,代碼行數:19,代碼來源:node-tests.ts

示例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;
}
開發者ID:knarfeh,項目名稱:eebookorg,代碼行數:6,代碼來源:util.ts

示例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;
}
開發者ID:PhilipDavis,項目名稱:react-redux,代碼行數:11,代碼來源:password.ts

示例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;
}
開發者ID:D10221,項目名稱:koapp,代碼行數:6,代碼來源:index.ts

示例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;
 }
開發者ID:chen-framework,項目名稱:chen,代碼行數:13,代碼來源:crypto.ts

示例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;
}
開發者ID:BCJTI,項目名稱:typescript-express-seed,代碼行數:6,代碼來源:funcgen.ts

示例15: encrypt

export function encrypt(text: string, key: string) {
    return evaluate('utf8', 'hex', text, createCipher(ALGORITHM, key));
}
開發者ID:consumr-project,項目名稱:cp,代碼行數:3,代碼來源:crypto.ts


注:本文中的crypto.createCipher函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。