Return Protobuf AttributeList.

@param $encryptedData
@param $wrappedReceiptKey
@param $pem

@return AttributeList
170860
public static function convertToProtobufAttributeList($encryptedData, $wrappedReceiptKey, $pem)
    {
        $decryptedCipherText = self::decryptCipherText(
            $encryptedData,
            $wrappedReceiptKey,
            $pem
        );

        $attributeList = new \Attrpubapi\AttributeList();
        $attributeList->mergeFromString($decryptedCipherText);

        return $attributeList;
    }
743408
public function decodePEM($pem_data)
    {
        $pem_data = $this->pemDataClean($pem_data);
        $decoded  = bin2hex(base64_decode($pem_data));

        $this->pemDataLenCheck($decoded);

        $ecpemstruct = array(
                             'oct_sec_val'  => substr($decoded, 14, 64),
                             'obj_id_val'   => substr($decoded, 86, 10),
                             'bit_str_val'  => substr($decoded, 106),
                            );

        $this->pemOidCheck($ecpemstruct['obj_id_val']);

        $private_key = $ecpemstruct['oct_sec_val'];
        $public_key  = '04' . $ecpemstruct['bit_str_val'];

        $this->pemKeyLenCheck(array($private_key, $public_key));

        return array(
                     'private_key' => $private_key,
                     'public_key'  => $public_key
                    );
    }
687467
def serialize_cert_to_pem(cert_obj):
    
    return cert_obj.public_bytes(
        encoding=cryptography.hazmat.primitives.serialization.Encoding.PEM
    )
162624
static SecretKey unwrap(SecretKey kek, byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException {
		final Cipher cipher = CipherSupplier.RFC3394_KEYWRAP.forUnwrapping(kek);
		try {
			return (SecretKey) cipher.unwrap(wrappedKey, wrappedKeyAlgorithm, wrappedKeyType);
		} catch (NoSuchAlgorithmException e) {
			throw new IllegalArgumentException("Invalid algorithm: " + wrappedKeyAlgorithm, e);
		}
	}
398695
def get_publickey(keydata):
    """"""
    try:
        key = serialization.load_pem_public_key(
            keydata,
            backend=default_backend(),
        )
        return key
    except ValueError:
        key = serialization.load_pem_private_key(
            keydata,
            password=None,
            backend=default_backend(),
        )
        key = key.public_key()
        return key
396570
public static function signatureRsa(string $data, string $privateKey, string $format = null): string
    {
        $key = \openssl_pkey_get_private($privateKey);
        if (!\openssl_sign($data, $signature, $key, OPENSSL_ALGO_SHA256)) {
            throw new CryptoException('RSA signature error: ' . openssl_error_string());
        }

        return self::fromRaw($signature, $format);
    }
107956
private function encryptFile(EncryptableFile $fileEntity, KeyData $keyData)
    {
        $file = $fileEntity->getFile();
        $encrypt = false;

        if ($file) {
            $filePath = $file->getRealPath();
            $encrypt = true;
        } elseif ($fileEntity->getId() && $fileEntity->fileExists() && !$fileEntity->isFileEncrypted()) {
            // The document was persisted but somehow the file was not encrypted
            $filePath = $fileEntity->getAbsolutePath();
            $encrypt = true;
        }

        if ($encrypt) {
            $fileContent = file_get_contents($filePath);
            // Get the encryption key data
            if ($keyData) {
                $encType = CryptographyProviderInterface::FILE_ENCRYPTION;
                $encryptedContent = $this->cryptographyProvider->encrypt($fileContent, $keyData, $encType);

                // Replace the file content with the encrypted
                file_put_contents($filePath, $encryptedContent);
                $fileEntity->setFileEncrypted(true);
            }
        }
    }
245670
private function parseFeedData($encryptedData, $decryptedData)
    {
        $orders = new \SimpleXMLElement($decryptedData);

        // loop over each transaction to find FoxyCart Order ID
        foreach ($orders->transactions->transaction as $transaction) {
            $this->processTransaction($transaction, $encryptedData);
        }
    }
915862
public static function importEncryptionSecretKey(HiddenString $keyData): EncryptionSecretKey
    {
        return new EncryptionSecretKey(
            new HiddenString(
                self::getKeyDataFromString(
                    Hex::decode($keyData->getString())
                )
            )
        );
    }
11167
public function privateKeyToDer($privateKey, $privateKyePassword = '')
    {
        try {
            if (strlen($privateKyePassword) === 0) {
                return CryptoVirgilKeyPair::privateKeyToDER($privateKey);
            }

            return CryptoVirgilKeyPair::privateKeyToDER(
                $this->encryptPrivateKey($privateKey, $privateKyePassword),
                $privateKyePassword
            );
        } catch (Exception $exception) {
            throw new PrivateKeyToDerConvertingException($exception->getMessage(), $exception->getCode());
        }
    }
53432
public static RSAPrivateKey getRSAPrivateKeyFromPEM(Provider provider, String pem) {
        try {
            KeyFactory keyFactory = KeyFactory.getInstance("RSA", provider);
            return (RSAPrivateKey) keyFactory.generatePrivate(new PKCS8EncodedKeySpec(getKeyBytesFromPEM(pem)));
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException("Algorithm SHA256withRSA is not available", e);
        } catch (InvalidKeySpecException e) {
            throw new IllegalArgumentException("Invalid PEM provided", e);
        }
    }
1333897
def rsa_decrypt(encrypted_data, pem, password=None):
    
    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

    encrypted_data = to_binary(encrypted_data)
    pem = to_binary(pem)
    private_key = serialization.load_pem_private_key(pem, password, backend=default_backend())
    data = private_key.decrypt(
        encrypted_data,
        padding=padding.OAEP(
            mgf=padding.MGF1(hashes.SHA1()),
            algorithm=hashes.SHA1(),
            label=None,
        )
    )
    return data
770471
def load_private_key(pem_path, passphrase_bytes=None):
    """"""
    with open(pem_path, "rb") as f:
        return cryptography.hazmat.primitives.serialization.load_pem_private_key(
            data=f.read(),
            password=passphrase_bytes,
            backend=cryptography.hazmat.backends.default_backend(),
        )
53766
private RSAPrivateKey loadPrivateKeyFromPEMFile(String filename) {
        try {
            String publicKeyFile = FileReader.readFileFromClassPathOrPath(filename);
            byte[] publicKeyBytes = DatatypeConverter.parseBase64Binary(publicKeyFile.replace("-----BEGIN RSA PRIVATE KEY-----", "").replace("-----END RSA PRIVATE KEY-----", ""));
            return (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(publicKeyBytes));
        } catch (Exception e) {
            throw new RuntimeException("Exception reading private key from PEM file", e);
        }
    }
491801
public static function getCNPJCert($certPem)
    {
        $certDer = self::pem2Der((string) $certPem);
        $data = self::getOIDdata((string) $certDer, '2.16.76.1.3.3');

        return (string) $data[0][1][1][0][1];
    }
622015
public SecretKey unwrapSecretKey(String wrappedKey) {

        return (SecretKey) unwrap(wrappedKey, Keys.SYMMETRIC_ALGORITHM,
                Cipher.SECRET_KEY, WRAP_ALGORITHM_SYMMETRIC);
    }
656762
public function decrypt($encrypted, $privateKey)
    {
        $rsa = new RSA();
        $rsa->loadKey($privateKey);

        return $rsa->decrypt($encrypted);
    }