diff options
author | Ingela Anderton Andin <[email protected]> | 2014-08-21 12:58:09 +0200 |
---|---|---|
committer | Ingela Anderton Andin <[email protected]> | 2014-08-25 09:04:46 +0200 |
commit | 34fa6383ea9e065a4555d2d263149893b8d7b1ad (patch) | |
tree | 152d1dbd66588983ff50ff4d4f8fad380c456d5c /lib/public_key/src/pubkey_pem.erl | |
parent | f993ce5f68f875f95c24f085773e4a0916568e9d (diff) | |
download | otp-34fa6383ea9e065a4555d2d263149893b8d7b1ad.tar.gz otp-34fa6383ea9e065a4555d2d263149893b8d7b1ad.tar.bz2 otp-34fa6383ea9e065a4555d2d263149893b8d7b1ad.zip |
public_key: Add encodeing functionality for PBES1 and PBES2
Diffstat (limited to 'lib/public_key/src/pubkey_pem.erl')
-rw-r--r-- | lib/public_key/src/pubkey_pem.erl | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/public_key/src/pubkey_pem.erl b/lib/public_key/src/pubkey_pem.erl index bee57a223d..8d2e97ad77 100644 --- a/lib/public_key/src/pubkey_pem.erl +++ b/lib/public_key/src/pubkey_pem.erl @@ -94,6 +94,10 @@ encode_pem_entries(Entries) -> encode_pem_entry({Type, Der, not_encrypted}) -> StartStr = pem_start(Type), [StartStr, "\n", b64encode_and_split(Der), "\n", pem_end(StartStr) ,"\n\n"]; +encode_pem_entry({'PrivateKeyInfo', Der, EncParams}) -> + EncDer = encode_encrypted_private_keyinfo(Der, EncParams), + StartStr = pem_start('EncryptedPrivateKeyInfo'), + [StartStr, "\n", b64encode_and_split(EncDer), "\n", pem_end(StartStr) ,"\n\n"]; encode_pem_entry({Type, Der, {Cipher, Salt}}) -> StartStr = pem_start(Type), [StartStr,"\n", pem_decrypt(),"\n", pem_decrypt_info(Cipher, Salt),"\n", @@ -139,6 +143,12 @@ decode_encrypted_private_keyinfo(Der) -> DecryptParams = pubkey_pbe:decrypt_parameters(AlgorithmInfo), {'PrivateKeyInfo', iolist_to_binary(Data), DecryptParams}. + +encode_encrypted_private_keyinfo(EncData, EncryptParmams) -> + AlgorithmInfo = pubkey_pbe:encrypt_parameters(EncryptParmams), + public_key:der_encode('EncryptedPrivateKeyInfo', + #'EncryptedPrivateKeyInfo'{encryptionAlgorithm = AlgorithmInfo, + encryptedData = EncData}). split_bin(Bin) -> split_bin(0, Bin). @@ -197,6 +207,8 @@ pem_start('DSAPrivateKey') -> <<"-----BEGIN DSA PRIVATE KEY-----">>; pem_start('DHParameter') -> <<"-----BEGIN DH PARAMETERS-----">>; +pem_start('EncryptedPrivateKeyInfo') -> + <<"-----BEGIN ENCRYPTED PRIVATE KEY-----">>; pem_start('CertificationRequest') -> <<"-----BEGIN CERTIFICATE REQUEST-----">>; pem_start('ContentInfo') -> |