<code>.google.privacy.dlp.v2.KmsWrappedCryptoKey kms_wrapped = 3;</code>
9936
public com.google.privacy.dlp.v2.KmsWrappedCryptoKeyOrBuilder getKmsWrappedOrBuilder() {
    if (sourceCase_ == 3) {
      return (com.google.privacy.dlp.v2.KmsWrappedCryptoKey) source_;
    }
    return com.google.privacy.dlp.v2.KmsWrappedCryptoKey.getDefaultInstance();
  }
241681
async function disableCryptoKeyVersion(
  projectId = 'your-project-id', // Your GCP Project ID
  keyRingId = 'my-key-ring', // Name of the crypto key version's key ring
  cryptoKeyId = 'my-key', // Name of the version's crypto key
  version = 1234 // The version's id
) {
  // Import the library and create a client
  const kms = require('@google-cloud/kms');
  const client = new kms.KeyManagementServiceClient();

  // The location of the crypto key versions's key ring, e.g. "global"
  const locationId = 'global';

  // Get the full path to the crypto key
  const name = client.cryptoKeyVersionPath(
    projectId,
    locationId,
    keyRingId,
    cryptoKeyId,
    version
  );

  // Gets a crypto key version
  const [cryptoKeyVersion] = await client.getCryptoKeyVersion({name});
  cryptoKeyVersion.state = 'DISABLED';

  // Disables a crypto key version
  const [result] = await client.updateCryptoKeyVersion({
    cryptoKeyVersion,
    updateMask: ['state'],
  });
  console.log(`Crypto key version ${result.name} disabled.`);
}
741515
function ObfuscatingStorageWrapper(storage) {

    var SECRET_KEY_KEY = "___XX";
    var wellKnownKey = "ce56c9aa-d287-4e7c-b9d5-edca7a985487";

    function getSecretKey() {
        var secretKeyName = scrambleKey(SECRET_KEY_KEY, wellKnownKey);
        var secretKey = storage.getItem(secretKeyName);
        if (secretKey === null) {
            secretKey = GuidGenerator();
            storage.setItem(secretKeyName, encryptValue(secretKey, wellKnownKey));
        }
        else {
            secretKey = decryptValue(secretKey, wellKnownKey);
        }
        return secretKey;
    }

    function scrambleKey(key, encryptionKey) {
        return CryptoJS.HmacMD5(key, encryptionKey || getSecretKey()).toString();
    }

    function encryptValue(value, encryptionKey) {
        return  CryptoJS.AES.encrypt(JSON.stringify(value), encryptionKey || getSecretKey()).toString();
    }

    function decryptValue(value, encryptionKey) {
        if (value === null) {
            return null;
        }
        try {
            var decryptedValue = CryptoJS.AES.decrypt(value, encryptionKey || getSecretKey()).toString(CryptoJS.enc.Utf8);
            return JSON.parse(decryptedValue);
        }
        catch (e) {
            return null;
        }
    }

    this.getItem = function (key) {
        return decryptValue(storage.getItem(scrambleKey(key)));
    };

    this.setItem = function (key, value) {
        storage.setItem(scrambleKey(key), encryptValue(value));
    };

    this.removeItem = function (key) {
        storage.removeItem(scrambleKey(key));
    };

    this.clear = function () {
        storage.clear();
    };

    getSecretKey();
}
163681
async function encrypt(
  projectId = 'your-project-id', // Your GCP projectId
  keyRingId = 'my-key-ring', // Name of the crypto key's key ring
  cryptoKeyId = 'my-key', // Name of the crypto key, e.g. "my-key"
  plaintextFileName = './path/to/plaintext.txt',
  ciphertextFileName = './path/to/plaintext.txt.encrypted'
) {
  const fs = require('fs');
  const {promisify} = require('util');

  // Import the library and create a client
  const kms = require('@google-cloud/kms');
  const client = new kms.KeyManagementServiceClient();

  // The location of the crypto key's key ring, e.g. "global"
  const locationId = 'global';

  // Reads the file to be encrypted
  const readFile = promisify(fs.readFile);
  const contentsBuffer = await readFile(plaintextFileName);
  const plaintext = contentsBuffer.toString('base64');
  const name = client.cryptoKeyPath(
    projectId,
    locationId,
    keyRingId,
    cryptoKeyId
  );

  // Encrypts the file using the specified crypto key
  const [result] = await client.encrypt({name, plaintext});
  const writeFile = promisify(fs.writeFile);
  await writeFile(ciphertextFileName, Buffer.from(result.ciphertext, 'base64'));
  console.log(`Encrypted ${plaintextFileName} using ${result.name}.`);
  console.log(`Result saved to ${ciphertextFileName}.`);
}
1166496
def kms_decrypt_value(self, lookup):
    
    decrypted_lookup = ef_utils.kms_decrypt(EFAwsResolver.__CLIENTS["kms"], lookup)
    return decrypted_lookup
294637
function crypto_sign(sm, m, n, sk) {
  var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
  var i, j, x = new Float64Array(64);
  var p = [gf(), gf(), gf(), gf()];

  crypto_hash(d, sk, 32);
  d[0] &= 248;
  d[31] &= 127;
  d[31] |= 64;

  var smlen = n + 64;
  for (i = 0; i < n; i++) sm[64 + i] = m[i];
  for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];

  crypto_hash(r, sm.subarray(32), n+32);
  reduce(r);
  scalarbase(p, r);
  pack(sm, p);

  for (i = 32; i < 64; i++) sm[i] = sk[i];
  crypto_hash(h, sm, n + 64);
  reduce(h);

  for (i = 0; i < 64; i++) x[i] = 0;
  for (i = 0; i < 32; i++) x[i] = r[i];
  for (i = 0; i < 32; i++) {
    for (j = 0; j < 32; j++) {
      x[i+j] += h[i] * d[j];
    }
  }

  modL(sm.subarray(32), x);
  return smlen;
}
963906
@Override
    public String incomingCrypted(String st, HBCIMsgStatus msgStatus, String msgName) {
        int idx = st.indexOf("'");
        if (idx != -1) {
            try {
                String msghead_st = st.substring(0, idx);
                int plusidx = 0;
                for (int i = 0; i < 5; i++)
                    plusidx = msghead_st.indexOf("+", plusidx + 1);
                if (plusidx == -1) {
                    log.warn("MsgRef is missing, adding it");
                    String[] des = {"dialogid", "msgnum"};
                    for (int i = 0; i < 2; i++) {
                        String temp = (msgStatus.getData().get("orig_" + msgName + ".MsgHead." + des[i]));
                        log.warn("setting MsgRef." + des[i] + " to " + temp);
                        msghead_st += (i == 0 ? "+" : ":");
                        msghead_st += temp;
                    }
                    st = new StringBuffer(st).replace(0, idx, msghead_st).toString();
                }
            } catch (Exception ex) {
                throw new HBCI_Exception("*** error while fixing missing MsgRef", ex);
            }
        }
        return st;
    }
1129538
async function encryptPBES2(binKey, passphrase, kdfAlgorithm, prf, iterationCount, cipher){
  // kdf
  const pBuffer = jseu.encoder.stringToArrayBuffer(passphrase);
  const salt = await jscrandom.getRandomBytes(
    params.keyDerivationFunctions[kdfAlgorithm].defaultSaltLen
  ); // TODO: currently only salt length of 8 is available
  const keyLength = params.encryptionSchemes[cipher].keyLength; // get keyLength

  let key;
  if (kdfAlgorithm === 'pbkdf2') {
    key = await pbkdf.pbkdf2(pBuffer, salt, iterationCount, keyLength, params.pbkdf2Prfs[prf].hash);
  } else throw new Error('UnsupportedKDF');

  // encrypt
  let iv;
  let encryptedData;
  if (cipher === 'des-ede3-cbc') { // TODO other encryption schemes
    iv = Buffer.from(await jscrandom.getRandomBytes(params.encryptionSchemes[cipher].ivLength));
    const CBC = des.CBC.instantiate(des.EDE);
    const ct = CBC.create({ type: 'encrypt', key: Buffer.from(key), iv });
    encryptedData = Buffer.from(ct.update(binKey).concat(ct.final()));
  }
  else if (cipher === 'aes128-cbc' || cipher === 'aes192-cbc' || cipher === 'aes256-cbc'){
    iv = await jscrandom.getRandomBytes(params.encryptionSchemes[cipher].ivLength);
    encryptedData = Buffer.from( await jscaes.encrypt(
      new Uint8Array(binKey), key, {name: 'AES-CBC', iv}
    ));
    iv = Buffer.from(iv);
  } else throw new Error('UnsupportedCipher');

  // structure
  return {
    encryptedData,
    encryptionAlgorithm: {
      algorithm: 'pbes2',
      parameters: {
        keyDerivationFunc: {
          algorithm: kdfAlgorithm,
          parameters: {
            salt: {type: 'specified', value: Buffer.from(salt)},
            iterationCount: new BN(iterationCount),
            prf: {algorithm: prf, parameters: Buffer.from([0x05, 0x00])}
          }
        },
        encryptionScheme: { algorithm: cipher, parameters: iv }
      }
    }
  };
}
181403
def encrypt(key, message):
    '''
    '''
    try:
        ret = kms.encrypt(KeyId=key, Plaintext=message)
        encrypted_data = base64.encodestring(ret.get('CiphertextBlob'))
    except Exception as e:
        # returns http 500 back to user and log error details in Cloudwatch Logs
        raise Exception("Unable to encrypt data: ", e)

    return encrypted_data.decode()
1085687
def encrypt(self, k, a, m):
        
        hkey = k[:_inbytes(self.keysize)]
        ekey = k[_inbytes(self.keysize):]

        # encrypt
        iv = _randombits(self.blocksize)
        cipher = Cipher(algorithms.AES(ekey), modes.CBC(iv),
                        backend=self.backend)
        encryptor = cipher.encryptor()
        padder = PKCS7(self.blocksize).padder()
        padded_data = padder.update(m) + padder.finalize()
        e = encryptor.update(padded_data) + encryptor.finalize()

        # mac
        t = self._mac(hkey, a, iv, e)

        return (iv, e, t)
1202967
async function createCryptoKeyVersion(
  projectId = 'YOUR_PROJECT_ID', // Your Google Cloud Platform project ID
  keyRingId = 'my-key-ring', // Name of the crypto key version's key ring, e.g. "my-key-ring"
  cryptoKeyId = 'my-key' // Name of the version's crypto key
) {
  // Import the library and create a client
  const kms = require('@google-cloud/kms');
  const client = new kms.KeyManagementServiceClient();

  // The location of the crypto key versions's key ring, e.g. "global"
  const locationId = 'global';

  // Get the full path to the crypto key
  const parent = client.cryptoKeyPath(
    projectId,
    locationId,
    keyRingId,
    cryptoKeyId
  );

  // Creates a new crypto key version
  const [result] = await client.createCryptoKeyVersion({parent});
  console.log(`Crypto key version ${result.name} created.`);
}
473449
function hmacSha256(key, data) {
    if (subtle) {
        var algo = { name: 'HMAC', hash: { name: 'SHA-256' } };
        return subtle.importKey('raw', key, algo, false, ['sign'])
            .then(function(subtleKey) {
                return subtle.sign(algo, subtleKey, data);
            });
    } else if (nodeCrypto) {
        return new Promise(function(resolve) {
            var hmac = nodeCrypto.createHmac('sha256', Buffer.from(key));
            var hash = hmac.update(Buffer.from(data)).digest();
            resolve(hash.buffer);
        });
    } else {
        return Promise.reject(new KdbxError(Consts.ErrorCodes.NotImplemented, 'HMAC-SHA256 not implemented'));
    }
}
382524
public com.google.privacy.dlp.v2.TransientCryptoKeyOrBuilder getTransientOrBuilder() {
    if (sourceCase_ == 1) {
      return (com.google.privacy.dlp.v2.TransientCryptoKey) source_;
    }
    return com.google.privacy.dlp.v2.TransientCryptoKey.getDefaultInstance();
  }
536196
def _api_decrypt():
    '''
    
    '''
    kms = _kms()
    data_key = _cfg_data_key()
    try:
        return kms.decrypt(CiphertextBlob=data_key)
    except botocore.exceptions.ClientError as orig_exc:
        error_code = orig_exc.response.get('Error', {}).get('Code', '')
        if error_code != 'InvalidCiphertextException':
            raise
        err_msg = 'aws_kms:data_key is not a valid KMS data key'
        config_error = salt.exceptions.SaltConfigurationError(err_msg)
        six.raise_from(config_error, orig_exc)
669844
async function restoreCryptoKeyVersion(
  projectId = 'your-project-id', // Your GCP projectId
  keyRingId = 'my-key-ring', // Name of the crypto key version's key ring
  cryptoKeyId = 'my-key', // Name of the version's crypto key
  version = 1234 // The version's id
) {
  // Import the library and create a client
  const kms = require('@google-cloud/kms');
  const client = new kms.KeyManagementServiceClient();

  // The location of the crypto key versions's key ring, e.g. "global"
  const locationId = 'global';

  // Get the full path to the crypto key version
  const name = client.cryptoKeyVersionPath(
    projectId,
    locationId,
    keyRingId,
    cryptoKeyId,
    version
  );

  // restores a crypto key version
  const [result] = await client.restoreCryptoKeyVersion({name});
  console.log(`Crypto key version ${result.name} restored.`);
}
335582
async function listCryptoKeyVersions(
  projectId = 'your-project-id', // Your GCP projectId
  keyRingId = 'my-key-ring', // name of the crypto key's key ring
  cryptoKeyId = 'my-key-ring' // name of the crypto key from which to list versions
) {
  // Import the library and create a client
  const kms = require('@google-cloud/kms');
  const client = new kms.KeyManagementServiceClient();

  // The location of the crypto key's key ring, e.g. "global"
  const locationId = 'global';

  // Get full path to crypto key
  const parent = client.cryptoKeyPath(
    projectId,
    locationId,
    keyRingId,
    cryptoKeyId
  );

  // Creates a new key ring
  const [versions] = await client.listCryptoKeyVersions({parent});
  if (versions.length) {
    versions.forEach(version => {
      console.log(`${version.name}:`);
      console.log(`  Created: ${new Date(version.createTime.seconds * 1000)}`);
      console.log(`  State: ${version.state}`);
    });
  } else {
    console.log('No crypto key versions found.');
  }
}
954265
function ekskey(data, key, engine, heap32) {
        var i, off, sw;
        var L_offset = LR_offset >> 2,
            R_offset = L_offset + 1;

        heap32[L_offset] = 0;
        heap32[R_offset] = 0;
        
        off = 0;
        for (i = 0; i < P_LEN; i++) {
            sw = key[off++] << 24 | key[off++] << 16 | key[off++] << 8 | key[off++];
            heap32[P_offset >> 2 | i] ^= sw;
        }
        
        off = 0;
        for (i = 0; i < P_LEN; i += 2) {
            sw = data[off++] << 24 | data[off++] << 16 | data[off++] << 8 | data[off++];
            off &= 0xff0f;   // &0xff0f === %BCRYPT_SALT_LEN
            heap32[L_offset] ^= sw;

            sw = data[off++] << 24 | data[off++] << 16 | data[off++] << 8 | data[off++];
            off &= 0xff0f;
            heap32[R_offset] ^= sw;

            engine.encrypt(LR_offset);
            heap32[P_offset >> 2 | i] = heap32[L_offset];
            heap32[P_offset >> 2 | (i + 1)] = heap32[R_offset];
        }
        
        var s_offset = S_offset >> 2;
        for (i = 0; i < S_LEN; i += 2) {
            sw = data[off++] << 24 | data[off++] << 16 | data[off++] << 8 | data[off++];
            off &= 0xff0f;   // &0xff0f === %BCRYPT_SALT_LEN
            heap32[L_offset] ^= sw;

            sw = data[off++] << 24 | data[off++] << 16 | data[off++] << 8 | data[off++];
            off &= 0xff0f;
            heap32[R_offset] ^= sw;

            engine.encrypt(LR_offset);
            heap32[s_offset | i] = heap32[L_offset];
            heap32[s_offset | (i + 1)] = heap32[R_offset];
        }
    }