Encrypt password using given RSA public key and encode it with base64.

    The encrypted password can only be decrypted by someone with the
    private key (in this case, only Travis).
542841
def encrypt(pubkey, password):
    
    key = load_key(pubkey)
    encrypted_password = key.encrypt(password, PKCS1v15())
    return base64.b64encode(encrypted_password)
276689
def _encrypt(data):
    """"""
    BS = AES.block_size

    def pad(s):
        n = BS - len(s) % BS
        char = chr(n).encode('utf8')
        return s + n * char

    password = settings.GECKOBOARD_PASSWORD
    salt = Random.new().read(BS - len('Salted__'))
    key, iv = _derive_key_and_iv(password, salt, 32, BS)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    encrypted = b'Salted__' + salt + cipher.encrypt(pad(data))
    return base64.b64encode(encrypted)
228023
private static byte[] encryptData(PublicKey publicKey, byte[] plainData)
			throws Exception {
		try {
			Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding","BC");
			cipher.init(Cipher.ENCRYPT_MODE, publicKey);
			return cipher.doFinal(plainData);
		} catch (Exception e) {
			throw new Exception(e.getMessage());
		}
	}
165132
public void decrypt(byte[] password) throws GeneralSecurityException {
        if (!isEncrypted()) {
            return;
        }

        byte[] enc = Base64.decode(this.encodedKey);

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

        Cipher cipher = getCipher();
        cipher.init(Cipher.DECRYPT_MODE, key, this.initializationVector);
        enc = cipher.doFinal(enc);

        this.intKey = getKey(this.keyAlg, enc);
        this.keyData = enc;
        this.isEncrypted = false;
        this.encodedKey = null;
    }
707809
public static function rsaPublicDecrypt(
        $str,
        $publicKeyPath,
        $padding = OPENSSL_PKCS1_PADDING,
        $format = self::FORMAT_HEX
    )
    {
        $str = trim($str);

        switch ($format) {
            case self::FORMAT_HEX:
                $str = hex2bin($str);
                break;
            case self::FORMAT_BASE64:
                $str = EncodeHelper::base64Decode($str);
                break;
            default:
                $str = hex2bin($str);
        }

        openssl_public_decrypt(
            $str,
            $decrypted,
            openssl_get_publickey(file_get_contents($publicKeyPath)),
            $padding
        );

        return trim($decrypted);
    }
953412
def encode(password, algorithm, salt, iterations):
    
    hash = hashlib.pbkdf2_hmac(digest().name, password.encode(), salt.encode(), iterations)
    encoded = base64.b64encode(hash).decode('ascii').strip()
    return "%s$%d$%s$%s" % (algorithm, iterations, salt, encoded)
787853
def encrypt(key_id, plaintext, encryption_context=None, grant_tokens=None,
            region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    r = {}
    try:
        ciphertext = conn.encrypt(
            key_id,
            plaintext,
            encryption_context=encryption_context,
            grant_tokens=grant_tokens
        )
        r['ciphertext'] = ciphertext['CiphertextBlob']
    except boto.exception.BotoServerError as e:
        r['error'] = __utils__['boto.get_error'](e)
    return r
344303
public static String decrypt(String base64Cipher, String priKey) {
        return new String(RSA.decrypt(Base64Util.decode(base64Cipher), decryptPrivateKey(priKey)));
    }
1320368
def encryptstring(text, password):
    

    enc = []
    for i in enumerate(text):
        key_c = password[i[0] % len(password)]
        enc_c = chr((ord(i[1]) + ord(key_c)) % 256)
        enc.append(enc_c)
    return base64.urlsafe_b64encode("".join(enc).encode()).decode()
1197480
def private_rsa
        if password
          options = {:password => password}
          options[:algorithm] = algorithm if algorithm
          
          private_key = @private_key.decrypt(:symmetric, options)
          OpenSSL::PKey::RSA.new(private_key)
        else
          @private_rsa ||= OpenSSL::PKey::RSA.new(@private_key)
        end
      end
67681
def jks_pkey_encrypt(key, password_str):
    
    password_bytes = password_str.encode('utf-16be') # Java chars are UTF-16BE code units
    iv = os.urandom(20)

    key = bytearray(key)
    xoring = zip(key, _jks_keystream(iv, password_bytes))
    data = bytearray([d^k for d,k in xoring])

    check = hashlib.sha1(bytes(password_bytes + key)).digest()
    return bytes(iv + data + check)
826768
public static void encryptAsync(String raw, String password, RNCryptorNativeCallback RNCryptorNativeCallback) {
        byte[] encrypted;
        try {
            encrypted = new RNCryptorNative().encrypt(raw, password);
            RNCryptorNativeCallback.done(new String(encrypted, "UTF-8"), null);
        } catch (Exception e) {
            RNCryptorNativeCallback.done(null, e);
        }

    }
132712
public function encrypt($str = null, $key = null)
    {
        if (!is_null($key)) {
            $this->setSalt($key);
        }
        srand((double)microtime()*1000000);
        $key_encrypt    = md5(rand(0,32000));
        $count          = 0;
        $tmp            = '';
        for ($ctr=0;$ctr<strlen($str);$ctr++) {
            if ($count==strlen($key_encrypt)) {
                $count=0;
            }
            $tmp.= substr($key_encrypt,$count,1).(substr($str,$ctr,1) ^ substr($key_encrypt,$count,1) );
            $count++;
        }
        return base64_encode(self::getEncryptionKey($tmp));
    }
441725
def address_from_public_key(pk_bytes):
    
    final_bytes = bytearray()

    # version
    final_bytes.append(6 << 3)
    # public key
    final_bytes.extend(pk_bytes)
    # checksum
    final_bytes.extend(struct.pack("<H", _crc16_checksum(final_bytes)))

    return base64.b32encode(final_bytes).decode()
59650
public final String encodeKeyStore(KeyStore keyStore, char[] password) {
        logger.entry();
        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            keyStore.store(out, password);
            out.flush();
            byte[] bytes = out.toByteArray();
            String encodedKeyStore = Base64Utils.encode(bytes);
            logger.exit();
            return encodedKeyStore;
        } catch (IOException | KeyStoreException | NoSuchAlgorithmException | CertificateException e) {
            RuntimeException exception = new RuntimeException("An unexpected exception occurred while attempting to encode a keystore.", e);
            logger.error(exception.toString());
            throw exception;
        }
    }
335691
def load_key(pubkey):
    
    try:
        return load_pem_public_key(pubkey.encode(), default_backend())
    except ValueError:
        # workaround for https://github.com/travis-ci/travis-api/issues/196
        pubkey = pubkey.replace('BEGIN RSA', 'BEGIN').replace('END RSA', 'END')
        return load_pem_public_key(pubkey.encode(), default_backend())
401925
def DecryptPassword(cipher, key):
		
		import base64
		import hmac
		import sha
		from array import array

		H = UcsUtils.GetShaHash

		cipher = cipher + "\n"
		cipher = base64.decodestring(cipher)
		n = len(cipher) - 16 - 8

		uhash = cipher[:16]
		passwordStream = cipher[16:-8] + "0000"[n & 3:]
		auth = cipher[-8:]

		k_enc, k_auth = H('enc' + key + uhash), H('auth' + key + uhash)
		vauth = hmac.new(cipher[-8:], k_auth, sha).digest()[:8]

		passwordStream = array('L', passwordStream)
		xkey = UcsUtils.Expandkey(k_enc, n + 4)

		for i in xrange(len(passwordStream)):
			passwordStream[i] = passwordStream[i] ^ xkey[i]

		decryptedPassword = passwordStream.tostring()[:n]
		return decryptedPassword