summary refs log tree commit diff
path: root/crypto/src/cms/KeyTransRecipientInformation.cs
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2021-05-24 13:06:31 +1000
committerDavid Hook <dgh@bouncycastle.org>2021-05-24 13:06:31 +1000
commit01238566c1d4b2a606e4859a75ad05ca79db4ffb (patch)
treeee7d1057d41cd25c3f0383b5d1ca2e213a976feb /crypto/src/cms/KeyTransRecipientInformation.cs
parentgithub#54 test for mixed mode definition (diff)
downloadBouncyCastle.NET-ed25519-01238566c1d4b2a606e4859a75ad05ca79db4ffb.tar.xz
github #222 addressed OAEP parameter setting, refactored KeyTransRecipientInfoGenerator to allow deprecation of sub class
Diffstat (limited to 'crypto/src/cms/KeyTransRecipientInformation.cs')
-rw-r--r--crypto/src/cms/KeyTransRecipientInformation.cs27
1 files changed, 20 insertions, 7 deletions
diff --git a/crypto/src/cms/KeyTransRecipientInformation.cs b/crypto/src/cms/KeyTransRecipientInformation.cs
index 7d2f072b5..2a40fed06 100644
--- a/crypto/src/cms/KeyTransRecipientInformation.cs
+++ b/crypto/src/cms/KeyTransRecipientInformation.cs
@@ -9,6 +9,8 @@ using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Security;
 using Org.BouncyCastle.X509;
+using Org.BouncyCastle.Asn1.Pkcs;
+using Org.BouncyCastle.Crypto.Operators;
 
 namespace Org.BouncyCastle.Cms
 {
@@ -42,7 +44,7 @@ namespace Org.BouncyCastle.Cms
                 }
                 else
                 {
-                    IssuerAndSerialNumber iAnds = IssuerAndSerialNumber.GetInstance(r.ID);
+                    Asn1.Cms.IssuerAndSerialNumber iAnds = Asn1.Cms.IssuerAndSerialNumber.GetInstance(r.ID);
 
 					rid.Issuer = iAnds.Name;
                     rid.SerialNumber = iAnds.SerialNumber.Value;
@@ -74,16 +76,27 @@ namespace Org.BouncyCastle.Cms
 		internal KeyParameter UnwrapKey(ICipherParameters key)
 		{
 			byte[] encryptedKey = info.EncryptedKey.GetOctets();
-            string keyExchangeAlgorithm = GetExchangeEncryptionAlgorithmName(keyEncAlg);
+            
 
 			try
 			{
-				IWrapper keyWrapper = WrapperUtilities.GetWrapper(keyExchangeAlgorithm);
-				keyWrapper.Init(false, key);
+				if (keyEncAlg.Algorithm.Equals(PkcsObjectIdentifiers.IdRsaesOaep))
+				{
+					IKeyUnwrapper keyWrapper = new Asn1KeyUnwrapper(keyEncAlg.Algorithm, keyEncAlg.Parameters, key);
 
-				// FIXME Support for MAC algorithm parameters similar to cipher parameters
-				return ParameterUtilities.CreateKeyParameter(
-					GetContentAlgorithmName(), keyWrapper.Unwrap(encryptedKey, 0, encryptedKey.Length));
+					return ParameterUtilities.CreateKeyParameter(
+							GetContentAlgorithmName(), keyWrapper.Unwrap(encryptedKey, 0, encryptedKey.Length).Collect());
+				}
+				else
+				{
+					string keyExchangeAlgorithm = GetExchangeEncryptionAlgorithmName(keyEncAlg);
+					IWrapper keyWrapper = WrapperUtilities.GetWrapper(keyExchangeAlgorithm);
+					keyWrapper.Init(false, key);
+
+					// FIXME Support for MAC algorithm parameters similar to cipher parameters
+					return ParameterUtilities.CreateKeyParameter(
+						GetContentAlgorithmName(), keyWrapper.Unwrap(encryptedKey, 0, encryptedKey.Length));
+				}
 			}
 			catch (SecurityUtilityException e)
 			{