[VARIABLE "new_encryption_key"]
190910
public Blob rotateBlobEncryptionKey(
      String bucketName, String blobName, String oldEncryptionKey, String newEncryptionKey) {
    // [START storageRotateEncryptionKey]
    BlobId blobId = BlobId.of(bucketName, blobName);
    CopyRequest request =
        CopyRequest.newBuilder()
            .setSource(blobId)
            .setSourceOptions(BlobSourceOption.decryptionKey(oldEncryptionKey))
            .setTarget(blobId, BlobTargetOption.encryptionKey(newEncryptionKey))
            .build();
    Blob blob = storage.copy(request).getResult();
    // [END storageRotateEncryptionKey]
    return blob;
  }
1255988
public static String encryptData(String key, String encryptedData, String iv) throws Exception {
        byte[] sessionKeyArray = Base64Utils.getInstance().decoder(key);
        byte[] encryptedDataArray = Base64Utils.getInstance().decoder(encryptedData);
        byte[] ivArray = Base64Utils.getInstance().decoder(iv);

        SecretKeySpec secretKey = new SecretKeySpec(sessionKeyArray, "AES");
        byte[] enCodeFormat = secretKey.getEncoded();
        SecretKeySpec secKey = new SecretKeySpec(enCodeFormat, "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");// 创建密码器
        cipher.init(Cipher.ENCRYPT_MODE, secKey, new IvParameterSpec(ivArray));// 初始化
        byte[] result = cipher.doFinal(encryptedDataArray);
        return new String(result);
    }
141529
public byte[] wrapKeyByKey(Key key,Key wrapKey)
	{
		try {
    		if(key==null ||wrapKey==null)
    		{
    			return null;
    		}
			Cipher cipher=Cipher.getInstance(algorithm);
			//使用私钥包裹模式
			cipher.init(Cipher.WRAP_MODE,wrapKey);
			return cipher.wrap(key);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
    	return null;
	}
95606
function _setupKey()
    {
        $key = $this->key;
        $keyLength = strlen($key);
        $keyStream = range(0, 255);
        $j = 0;
        for ($i = 0; $i < 256; $i++) {
            $j = ($j + $keyStream[$i] + ord($key[$i % $keyLength])) & 255;
            $temp = $keyStream[$i];
            $keyStream[$i] = $keyStream[$j];
            $keyStream[$j] = $temp;
        }

        $this->stream = array();
        $this->stream[self::DECRYPT] = $this->stream[self::ENCRYPT] = array(
            0, // index $i
            0, // index $j
            $keyStream
        );
    }
562726
function(key) {
  this.buffer = new Uint8Array(16);
  this.r = new Uint16Array(10);
  this.h = new Uint16Array(10);
  this.pad = new Uint16Array(8);
  this.leftover = 0;
  this.fin = 0;

  var t0, t1, t2, t3, t4, t5, t6, t7;

  t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0                     ) & 0x1fff;
  t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 <<  3)) & 0x1fff;
  t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 <<  6)) & 0x1f03;
  t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>>  7) | (t3 <<  9)) & 0x1fff;
  t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>>  4) | (t4 << 12)) & 0x00ff;
  this.r[5] = ((t4 >>>  1)) & 0x1ffe;
  t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 <<  2)) & 0x1fff;
  t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 <<  5)) & 0x1f81;
  t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>>  8) | (t7 <<  8)) & 0x1fff;
  this.r[9] = ((t7 >>>  5)) & 0x007f;

  this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
  this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
  this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
  this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
  this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
  this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
  this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
  this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
}
1118201
function _setupKey()
    {
        $key = $this->key;
        $keyLength = strlen($key);
        $keyStream = range(0, 255);
        $j = 0;
        for ($i = 0; $i < 256; $i++) {
            $j = ($j + $keyStream[$i] + ord($key[$i % $keyLength])) & 255;
            $temp = $keyStream[$i];
            $keyStream[$i] = $keyStream[$j];
            $keyStream[$j] = $temp;
        }

        $this->stream = array();
        $this->stream[CRYPT_RC4_DECRYPT] = $this->stream[CRYPT_RC4_ENCRYPT] = array(
            0, // index $i
            0, // index $j
            $keyStream
        );
    }
712531
function(key, data) {
        var shaObj = new Sha('SHA-256', 'TEXT');
        shaObj.setHMACKey(key, 'TEXT');
        shaObj.update(data);
        return shaObj.getHMAC('HEX');
    }
690608
function writeKey(key, value, masterPassword) {
    var contents = getContents(masterPassword);
    contents[key] = value;
    var fileContents = JSON.stringify(contents);
    var encryptedFileContents = encryption.encrypt(fileContents, masterPassword);
    file.writeToFile(encryptedFileContents);
}
191525
private static boolean initDES(String key) throws NoSuchAlgorithmException, NoSuchPaddingException {
        Security.addProvider(new com.sun.crypto.provider.SunJCE());
        // DES、DESede、AES为对称加密，RSA为非对称加密
        if (DES_CRYPT_WAY.equals(key)) {
            KeyGenerator keygen = KeyGenerator.getInstance(key);
            secretKey = keygen.generateKey();
            cipher = Cipher.getInstance(key);
            DES = 1;
        } else if (DES3_CRYPT_WAY.equals(key)) {
            KeyGenerator keygen = KeyGenerator.getInstance(key);
            secretKey3 = keygen.generateKey();
            cipher3 = Cipher.getInstance(key);
            DES3 = 1;
        } else if (AES_CRYPT_WAY.equals(key)) {
            KeyGenerator keygen = KeyGenerator.getInstance(key);
            aesKey = keygen.generateKey();
            aes = Cipher.getInstance(key);
            AES = 1;
        } else {
            // RSA加密
            KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(key);
            keyPairGen.initialize(1024);
            rsaKey = keyPairGen.generateKeyPair();
            rsa = Cipher.getInstance(key);
            RSA = 1;
        }
        return true;
    }
456687
private static KeyPair newKeyPair() throws Exception {
        KeyPairGenerator kpGen = KeyPairGenerator.getInstance(KEY_ALGORITHM, BC);
        kpGen.initialize(KEY_LENGTH, new SecureRandom());
        return kpGen.generateKeyPair();
    }
1356637
def new(cls, alias, sealed_obj, algorithm, key, key_size):
        
        timestamp = int(time.time()) * 1000

        raise NotImplementedError("Creating Secret Keys not implemented")
321470
def generated_key(key):
    """"""
    key_name = key['name']
    if key['method'] == 'uuid':
        LOG.debug("Setting %s to a uuid", key_name)
        return str(uuid4())
    elif key['method'] == 'words':
        LOG.debug("Setting %s to random words", key_name)
        return random_word()
    elif key['method'] == 'static':
        if 'value' not in key.keys():
            raise aomi.exceptions.AomiData("Missing static value")

        LOG.debug("Setting %s to a static value", key_name)
        return key['value']
    else:
        raise aomi.exceptions.AomiData("Unexpected generated secret method %s"
                                       % key['method'])
386317
def encrypt(message, key: nil)

      raise ArgumentError.new('The message argument is required.') if message.blank?
      raise ArgumentError.new('The key argument is required.')     if key.blank?

      cipher = OpenSSL::Cipher::AES.new(256, 'CBC')
      cipher.encrypt
      cipher.padding = aes_256_padding
      cipher.key     = key

      cipher.update(message)+cipher.final

    end
389608
function encrypt(data, key) {
    return Promise.resolve().then(function() {
        var bytesLeft = data.byteLength;
        var currentOffset = 0, blockIndex = 0, totalLength = 0;
        var buffers = [];

        var next = function() {
            var blockLength = Math.min(BlockSize, bytesLeft);
            bytesLeft -= blockLength;

            var blockData = data.slice(currentOffset, currentOffset + blockLength);
            return getBlockHmac(key, blockIndex, blockLength, blockData).then(function(blockHash) {
                var blockBuffer = new ArrayBuffer(32 + 4);
                var stm = new BinaryStream(blockBuffer);
                stm.writeBytes(blockHash);
                stm.setUint32(blockLength, true);

                buffers.push(blockBuffer);
                totalLength += blockBuffer.byteLength;

                if (blockData.byteLength > 0) {
                    buffers.push(blockData);
                    totalLength += blockData.byteLength;
                    blockIndex++;
                    currentOffset += blockLength;
                    return next();
                } else {
                    var ret = new Uint8Array(totalLength);
                    var offset = 0;
                    for (var i = 0; i < buffers.length; i++) {
                        ret.set(new Uint8Array(buffers[i]), offset);
                        offset += buffers[i].byteLength;
                    }
                    return ret.buffer;
                }
            });
        };
        return next();
    });
}
865359
def encrypt(self, key):
        
        if (self.encrypted):
            return
        # encrypt
        self.iv = Random.new().read(AES.block_size)
        aes = AES.new(key, AES.MODE_CFB, self.iv)
        self.f_key = aes.encrypt(self.f_key)
        self.alpha_key = aes.encrypt(self.alpha_key)
        self.encrypted = True
        # sign
        self.hmac = self.get_hmac(key)
1107738
public static String encryptData(String dataString, String encoding,
			PublicKey key) {
		/** 使用公钥对密码加密 **/
		byte[] data = null;
		try {
			data = encryptData(key, dataString.getBytes(encoding));
			return new String(SecureUtil.base64Encode(data), encoding);
		} catch (Exception e) {
			LogUtil.writeErrorLog(e.getMessage(), e);
			return "";
		}
	}
1111024
public static byte[] encrypt(byte[] data, byte[] key) {
        checkNotNull(data);
        checkNotNull(key);
        checkArgument(key.length >= 5 && key.length <= 256);
        StreamCipher rc4 = new RC4Engine();
        rc4.init(true, new KeyParameter(key));
        byte[] encrypted = new byte[data.length];
        rc4.processBytes(data, 0, data.length, encrypted, 0);
        return encrypted;
    }