aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public_key/src/pubkey_pem.erl
diff options
context:
space:
mode:
authorIngela Anderton Andin <[email protected]>2014-08-26 09:53:03 +0200
committerIngela Anderton Andin <[email protected]>2014-08-26 09:53:03 +0200
commit83113d9f1df48dc73fbff82705e8aa3fb3af6723 (patch)
tree5fcfe90eede8d72cead1cf9999ebc9cf64137b92 /lib/public_key/src/pubkey_pem.erl
parent7003ce74a2dfe183c3f0dff5a0500ec611721e16 (diff)
parent34fa6383ea9e065a4555d2d263149893b8d7b1ad (diff)
downloadotp-83113d9f1df48dc73fbff82705e8aa3fb3af6723.tar.gz
otp-83113d9f1df48dc73fbff82705e8aa3fb3af6723.tar.bz2
otp-83113d9f1df48dc73fbff82705e8aa3fb3af6723.zip
Merge branch 'ia/public_key/PBES2/OTP-11915' into maint
* ia/public_key/PBES2/OTP-11915: public_key: Add encodeing functionality for PBES1 and PBES2 public_key: Add PBES1 decoding support
Diffstat (limited to 'lib/public_key/src/pubkey_pem.erl')
-rw-r--r--lib/public_key/src/pubkey_pem.erl12
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') ->