summary refs log tree commit diff
path: root/crypto/src/pkcs
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2020-11-17 14:49:04 +1100
committerDavid Hook <dgh@cryptoworkshop.com>2020-11-17 14:49:04 +1100
commit19d5b6c6e5838c37ff48b11df1301a07a521fe4c (patch)
tree9635e77661cd5b1c066d5b866bcabfbb779da28a /crypto/src/pkcs
parentRework D/E range restriction (diff)
downloadBouncyCastle.NET-ed25519-19d5b6c6e5838c37ff48b11df1301a07a521fe4c.tar.xz
added suport for PKCS#5 scheme 2, tests for the same
Diffstat (limited to 'crypto/src/pkcs')
-rw-r--r--crypto/src/pkcs/Pkcs12Store.cs23
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