Encrypts a value with PBEWithSHAAndTwofishCBC, assuming PKCS#12-generated PBE parameters.
    (Not explicitly defined as an algorithm in RFC 7292, but defined here nevertheless because of the assumption of PKCS#12 parameters).
771331
def encrypt_PBEWithSHAAndTwofishCBC(plaintext_data, password, salt, iteration_count):
    
    iv  = derive_key(hashlib.sha1, PURPOSE_IV_MATERIAL,  password, salt, iteration_count, 16)
    key = derive_key(hashlib.sha1, PURPOSE_KEY_MATERIAL, password, salt, iteration_count, 256//8)

    plaintext_data = add_pkcs7_padding(plaintext_data, 16)
    plaintext_data = bytearray(plaintext_data)
    plaintext_len = len(plaintext_data)
    assert plaintext_len % 16 == 0

    ciphertext = bytearray()

    from twofish import Twofish
    cipher = Twofish(key)

    last_cipher_block = bytearray(iv)
    for block_offset in range(0, plaintext_len, 16):
        plaintext_block = plaintext_data[block_offset:block_offset+16]
        cipher_block = bytearray(cipher.encrypt(bytes(xor_bytearrays(plaintext_block, last_cipher_block))))
        ciphertext.extend(cipher_block)
        last_cipher_block = cipher_block

    return bytes(ciphertext)
187484
public static int encrypt(int value, byte[] key) {
		int[] buf = new int[4];
		buf[0] = ((value >> 24) & 0xff);
		buf[1] = ((value >> 16) & 0xff);
		buf[2] = ((value >> 8) & 0xff);
		buf[3] = ((value >> 0) & 0xff);

		skip32(key, buf, true);

		int out = ((buf[0]) << 24) | ((buf[1]) << 16) | ((buf[2]) << 8)
				| (buf[3]);

		return out;
	}
231904
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        int nciphers = SMBUtil.readInt2(buffer, bufferIndex);
        bufferIndex += 2;

        this.ciphers = new int[nciphers];
        for ( int i = 0; i < nciphers; i++ ) {
            this.ciphers[ i ] = SMBUtil.readInt2(buffer, bufferIndex);
            bufferIndex += 2;
        }

        return bufferIndex - start;
    }
315767
def encrypt_password(**kwargs):
    
    new_value = kwargs['new_value']
    field = kwargs['field']
    min_length = field.params['min_length']
    if len(new_value) < min_length:
        raise ValueError(
            '`{}`: Value length must be more than {}'.format(
                field.name, field.params['min_length']))

    if new_value and not crypt.match(new_value):
        new_value = str(crypt.encode(new_value))
    return new_value
944150
public byte[] encrypt(String iv, String message, Encoder encoder) {
        return encrypt(encoder.decode(iv), encoder.decode(message));
    }
70594
def RSA_encrypt(public_key, message):
    '''
    '''
    # 如果没能成功导入RSA模块, 就直接返回空白字符串.
    if not globals().get('RSA'):
        return ''
    rsakey = RSA.importKey(public_key)
    rsakey = PKCS1_v1_5.new(rsakey)
    encrypted = rsakey.encrypt(message.encode())
    return base64.encodestring(encrypted).decode().replace('\n', '')
967681
public void encrypt(byte[] password) throws GeneralSecurityException {

        if (isEncrypted()) {
            return;
        }

        if (this.encAlg == null) {
            setEncryptionAlgorithm("DES-EDE3-CBC");
        }

        if (this.ivData == null) {
            generateIV();
        }

        Key key = getSecretKey(password, this.initializationVector.getIV());

        Cipher cipher = getCipher();
        cipher.init(Cipher.ENCRYPT_MODE, key, this.initializationVector);

        /* encrypt the raw PKCS11 */

        this.keyData = cipher.doFinal(getEncoded(this.intKey));
        this.isEncrypted = true;
        this.encodedKey = null;
    }
595613
public static String encrypt(String input, String key, String algorithm, byte[] ivOrSalt, int iterations, String encoding, String charset) throws PageException {

	try {

	    if (charset == null) charset = DEFAULT_CHARSET;
	    if (encoding == null) encoding = DEFAULT_ENCODING;

	    byte[] baInput = input.getBytes(charset);
	    byte[] encrypted = encrypt(baInput, key, algorithm, ivOrSalt, iterations);

	    return Coder.encode(encoding, encrypted);
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	    throw Caster.toPageException(t);
	}
    }
561529
def crypto_box(message, nonce, pk, sk):
    
    if len(nonce) != crypto_box_NONCEBYTES:
        raise exc.ValueError("Invalid nonce size")

    if len(pk) != crypto_box_PUBLICKEYBYTES:
        raise exc.ValueError("Invalid public key")

    if len(sk) != crypto_box_SECRETKEYBYTES:
        raise exc.ValueError("Invalid secret key")

    padded = (b"\x00" * crypto_box_ZEROBYTES) + message
    ciphertext = ffi.new("unsigned char[]", len(padded))

    rc = lib.crypto_box(ciphertext, padded, len(padded), nonce, pk, sk)
    ensure(rc == 0,
           'Unexpected library error',
           raising=exc.RuntimeError)

    return ffi.buffer(ciphertext, len(padded))[crypto_box_BOXZEROBYTES:]
411646
def encode_uleb128(value)
      raise ArgumentError, "Signed integers are not supported" if value < 0
      return "\x00" if value == 0
      bytes = []
      while value != 0
        byte = value & 0b01111111 # 0x7f
        value >>= 7
        if value != 0
          byte |= 0b10000000 # 0x80
        end
        bytes << byte
      end
      return BTC::Data.data_from_bytes(bytes)
    end
931728
def encryptParams(self, params, key):
        
        keypair = Curve.generateKeyPair()
        encodedparams = self.urlencodeParams(params)

        cipher = AESGCM(Curve.calculateAgreement(key, keypair.privateKey))
        ciphertext = cipher.encrypt(b'\x00\x00\x00\x00' + struct.pack('>Q', 0), encodedparams.encode(), b'')

        payload = base64.b64encode(keypair.publicKey.serialize()[1:] + ciphertext)
        return [('ENC', payload)]
1016954
private static ByteBuf append(ByteBufAllocator allocator, boolean useDirect,
            X509Certificate cert, int count, ByteBuf pem) throws CertificateEncodingException {

        ByteBuf encoded = Unpooled.wrappedBuffer(cert.getEncoded());
        try {
            ByteBuf base64 = SslUtils.toBase64(allocator, encoded);
            try {
                if (pem == null) {
                    // We try to approximate the buffer's initial size. The sizes of
                    // certificates can vary a lot so it'll be off a bit depending
                    // on the number of elements in the array (count argument).
                    pem = newBuffer(allocator, useDirect,
                            (BEGIN_CERT.length + base64.readableBytes() + END_CERT.length) * count);
                }

                pem.writeBytes(BEGIN_CERT);
                pem.writeBytes(base64);
                pem.writeBytes(END_CERT);
            } finally {
                base64.release();
            }
        } finally {
            encoded.release();
        }

        return pem;
    }
318647
def encrypt(self, binary, use_sign=True):
        
        token = rsa.encrypt(binary, self.his_pubkey)  # encrypt it
        if use_sign:
            self.sign = rsa.sign(binary, self.my_privkey, "SHA-1")  # sign it
        return token
796536
public static String bcrypt(String s) {
		return (s == null) ? s : BCrypt.hashpw(s, BCrypt.gensalt(12));
	}
1120117
function rsaOaepEncrypt(cek, key) {
  if (key instanceof Buffer) {
    key = key.toString();
  } else if (typeof key !== 'string') {
    throw new TypeError('Key must be a buffer or a string');
  }
  if (!key.includes('-----BEGIN') ||
      !(key.includes('KEY-----') || key.includes('CERTIFICATE-----'))) {
    throw new TypeError('Key must be a PEM formatted RSA public key');
  }
  let options = {key: key, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING};
  return buf2b64url(crypto.publicEncrypt(options, cek));
}
314030
public void encryptBlock(byte[] data, int offset, byte[] dest, int destOffset) {
        // w128_t x;
        // x.q[0] = ((uint64_t *) blk)[0];
        // x.q[1] = ((uint64_t *) blk)[1];
        Kuz128 x = new Kuz128();
        x.setQ(0, ByteStrings.bytesToLong(data, offset));
        x.setQ(1, ByteStrings.bytesToLong(data, offset + 8));

        for (int i = 0; i < 9; i++) {
            // x.q[0] ^= key->k[i].q[0];
            // x.q[1] ^= key->k[i].q[1];
            x.setQ(0, x.getQ(0) ^ key.getK()[i].getQ(0));
            x.setQ(1, x.getQ(1) ^ key.getK()[i].getQ(1));

            for (int j = 0; j < 16; j++) {
                // x.b[j] = kuz_pi[x.b[j]];
                x.getB()[j] = KuznechikTables.kuz_pi[(x.getB()[j] & 0xFF)];
            }
            // kuz_l(&x);
            KuznechikMath.kuz_l(x);
        }

        // ((uint64_t *) blk)[0] = x.q[0] ^ key->k[9].q[0];
        // ((uint64_t *) blk)[1] = x.q[1] ^ key->k[9].q[1];
        ByteStrings.write(dest, destOffset, ByteStrings.longToBytes(x.getQ(0) ^ key.getK()[9].getQ(0)), 0, 8);
        ByteStrings.write(dest, destOffset + 8, ByteStrings.longToBytes(x.getQ(1) ^ key.getK()[9].getQ(1)), 0, 8);
    }
773434
def rsa_encrypt(data, pem, b64_encode=True):
    
    from cryptography.hazmat.backends import default_backend
    from cryptography.hazmat.primitives import serialization
    from cryptography.hazmat.primitives import hashes
    from cryptography.hazmat.primitives.asymmetric import padding
    encoded_data = to_binary(data)
    pem = to_binary(pem)
    public_key = serialization.load_pem_public_key(pem, backend=default_backend())
    encrypted_data = public_key.encrypt(
        encoded_data,
        padding=padding.OAEP(
            mgf=padding.MGF1(hashes.SHA1()),
            algorithm=hashes.SHA1(),
            label=None,
        )
    )
    if b64_encode:
        encrypted_data = base64.b64encode(encrypted_data).decode('utf-8')
    return encrypted_data