diff options
Diffstat (limited to 'crypto/src/pkcs/Pkcs12Store.cs')
-rw-r--r-- | crypto/src/pkcs/Pkcs12Store.cs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/crypto/src/pkcs/Pkcs12Store.cs b/crypto/src/pkcs/Pkcs12Store.cs index 0eff8eb92..dba76cdb5 100644 --- a/crypto/src/pkcs/Pkcs12Store.cs +++ b/crypto/src/pkcs/Pkcs12Store.cs @@ -1058,16 +1058,27 @@ namespace Org.BouncyCastle.Pkcs bool wrongPkcs12Zero, byte[] data) { - IBufferedCipher cipher = PbeUtilities.CreateEngine(algId.Algorithm) as IBufferedCipher; + IBufferedCipher cipher = PbeUtilities.CreateEngine(algId) as IBufferedCipher; if (cipher == null) throw new Exception("Unknown encryption algorithm: " + algId.Algorithm); - Pkcs12PbeParams pbeParameters = Pkcs12PbeParams.GetInstance(algId.Parameters); - ICipherParameters cipherParams = PbeUtilities.GenerateCipherParameters( - algId.Algorithm, password, wrongPkcs12Zero, pbeParameters); - cipher.Init(forEncryption, cipherParams); - return cipher.DoFinal(data); + if (algId.Algorithm.Equals(PkcsObjectIdentifiers.IdPbeS2)) + { + PbeS2Parameters pbeParameters = PbeS2Parameters.GetInstance(algId.Parameters); + ICipherParameters cipherParams = PbeUtilities.GenerateCipherParameters( + algId.Algorithm, password, pbeParameters); + cipher.Init(forEncryption, cipherParams); + return cipher.DoFinal(data); + } + else + { + Pkcs12PbeParams pbeParameters = Pkcs12PbeParams.GetInstance(algId.Parameters); + ICipherParameters cipherParams = PbeUtilities.GenerateCipherParameters( + algId.Algorithm, password, wrongPkcs12Zero, pbeParameters); + cipher.Init(forEncryption, cipherParams); + return cipher.DoFinal(data); + } } private class IgnoresCaseHashtable |