diff --git a/crypto/src/pkcs/Pkcs10CertificationRequest.cs b/crypto/src/pkcs/Pkcs10CertificationRequest.cs
index 1789f2a70..c2504e6e5 100644
--- a/crypto/src/pkcs/Pkcs10CertificationRequest.cs
+++ b/crypto/src/pkcs/Pkcs10CertificationRequest.cs
@@ -344,7 +344,7 @@ namespace Org.BouncyCastle.Pkcs
Platform.Dispose(streamCalculator.Stream);
- return ((IVerifier)streamCalculator.GetResult()).IsVerified(sigBits.GetBytes());
+ return ((IVerifier)streamCalculator.GetResult()).IsVerified(sigBits.GetOctets());
}
catch (Exception e)
{
@@ -379,7 +379,7 @@ namespace Org.BouncyCastle.Pkcs
// throw new SignatureException("IOException decoding parameters: " + e.Message);
// }
- if (signature.AlgorithmName.EndsWith("MGF1"))
+ if (Platform.EndsWith(signature.AlgorithmName, "MGF1"))
{
throw Platform.CreateNotImplementedException("signature algorithm with MGF1");
@@ -402,14 +402,14 @@ namespace Org.BouncyCastle.Pkcs
if (asn1Params != null && !(asn1Params is Asn1Null))
{
- if (sigAlgId.ObjectID.Equals(PkcsObjectIdentifiers.IdRsassaPss))
+ if (sigAlgId.Algorithm.Equals(PkcsObjectIdentifiers.IdRsassaPss))
{
RsassaPssParameters rsaParams = RsassaPssParameters.GetInstance(asn1Params);
- return GetDigestAlgName(rsaParams.HashAlgorithm.ObjectID) + "withRSAandMGF1";
+ return GetDigestAlgName(rsaParams.HashAlgorithm.Algorithm) + "withRSAandMGF1";
}
}
- return sigAlgId.ObjectID.Id;
+ return sigAlgId.Algorithm.Id;
}
private static string GetDigestAlgName(
diff --git a/crypto/src/pkcs/Pkcs12Store.cs b/crypto/src/pkcs/Pkcs12Store.cs
index ba3c208e8..52760f89b 100644
--- a/crypto/src/pkcs/Pkcs12Store.cs
+++ b/crypto/src/pkcs/Pkcs12Store.cs
@@ -213,7 +213,7 @@ namespace Org.BouncyCastle.Pkcs
byte[] data = ((Asn1OctetString) info.Content).GetOctets();
- byte[] mac = CalculatePbeMac(algId.ObjectID, salt, itCount, password, false, data);
+ byte[] mac = CalculatePbeMac(algId.Algorithm, salt, itCount, password, false, data);
byte[] dig = dInfo.GetDigest();
if (!Arrays.ConstantTimeAreEqual(mac, dig))
@@ -222,7 +222,7 @@ namespace Org.BouncyCastle.Pkcs
throw new IOException("PKCS12 key store MAC invalid - wrong password or corrupted file.");
// Try with incorrect zero length password
- mac = CalculatePbeMac(algId.ObjectID, salt, itCount, password, true, data);
+ mac = CalculatePbeMac(algId.Algorithm, salt, itCount, password, true, data);
if (!Arrays.ConstantTimeAreEqual(mac, dig))
throw new IOException("PKCS12 key store MAC invalid - wrong password or corrupted file.");
@@ -1015,14 +1015,14 @@ namespace Org.BouncyCastle.Pkcs
bool wrongPkcs12Zero,
byte[] data)
{
- IBufferedCipher cipher = PbeUtilities.CreateEngine(algId.ObjectID) as IBufferedCipher;
+ IBufferedCipher cipher = PbeUtilities.CreateEngine(algId.Algorithm) as IBufferedCipher;
if (cipher == null)
- throw new Exception("Unknown encryption algorithm: " + algId.ObjectID);
+ throw new Exception("Unknown encryption algorithm: " + algId.Algorithm);
Pkcs12PbeParams pbeParameters = Pkcs12PbeParams.GetInstance(algId.Parameters);
ICipherParameters cipherParams = PbeUtilities.GenerateCipherParameters(
- algId.ObjectID, password, wrongPkcs12Zero, pbeParameters);
+ algId.Algorithm, password, wrongPkcs12Zero, pbeParameters);
cipher.Init(forEncryption, cipherParams);
return cipher.DoFinal(data);
}
@@ -1052,13 +1052,13 @@ namespace Org.BouncyCastle.Pkcs
public object Remove(
string alias)
{
- string lower = Platform.ToLowerInvariant(alias);
- string k = (string) keys[lower];
+ string upper = Platform.ToUpperInvariant(alias);
+ string k = (string)keys[upper];
if (k == null)
return null;
- keys.Remove(lower);
+ keys.Remove(upper);
object o = orig[k];
orig.Remove(k);
@@ -1070,8 +1070,8 @@ namespace Org.BouncyCastle.Pkcs
{
get
{
- string lower = Platform.ToLowerInvariant(alias);
- string k = (string)keys[lower];
+ string upper = Platform.ToUpperInvariant(alias);
+ string k = (string)keys[upper];
if (k == null)
return null;
@@ -1080,13 +1080,13 @@ namespace Org.BouncyCastle.Pkcs
}
set
{
- string lower = Platform.ToLowerInvariant(alias);
- string k = (string)keys[lower];
+ string upper = Platform.ToUpperInvariant(alias);
+ string k = (string)keys[upper];
if (k != null)
{
orig.Remove(k);
}
- keys[lower] = alias;
+ keys[upper] = alias;
orig[alias] = value;
}
}
diff --git a/crypto/src/pkcs/Pkcs12Utilities.cs b/crypto/src/pkcs/Pkcs12Utilities.cs
index d35c8b6a2..923eca5a5 100644
--- a/crypto/src/pkcs/Pkcs12Utilities.cs
+++ b/crypto/src/pkcs/Pkcs12Utilities.cs
@@ -56,10 +56,10 @@ namespace Org.BouncyCastle.Pkcs
int itCount = mData.IterationCount.IntValue;
byte[] data = Asn1OctetString.GetInstance(info.Content).GetOctets();
byte[] res = Pkcs12Store.CalculatePbeMac(
- mData.Mac.AlgorithmID.ObjectID, mData.GetSalt(), itCount, passwd, false, data);
+ mData.Mac.AlgorithmID.Algorithm, mData.GetSalt(), itCount, passwd, false, data);
AlgorithmIdentifier algId = new AlgorithmIdentifier(
- mData.Mac.AlgorithmID.ObjectID, DerNull.Instance);
+ mData.Mac.AlgorithmID.Algorithm, DerNull.Instance);
DigestInfo dInfo = new DigestInfo(algId, res);
mData = new MacData(dInfo, mData.GetSalt(), itCount);
diff --git a/crypto/src/pkcs/PrivateKeyInfoFactory.cs b/crypto/src/pkcs/PrivateKeyInfoFactory.cs
index 723d50f08..a349a11d2 100644
--- a/crypto/src/pkcs/PrivateKeyInfoFactory.cs
+++ b/crypto/src/pkcs/PrivateKeyInfoFactory.cs
@@ -106,49 +106,46 @@ namespace Org.BouncyCastle.Pkcs
if (key is ECPrivateKeyParameters)
{
- ECPrivateKeyParameters _key = (ECPrivateKeyParameters)key;
+ ECPrivateKeyParameters priv = (ECPrivateKeyParameters)key;
+ ECDomainParameters dp = priv.Parameters;
+ int orderBitLength = dp.N.BitLength;
+
AlgorithmIdentifier algID;
ECPrivateKeyStructure ec;
- if (_key.AlgorithmName == "ECGOST3410")
+ if (priv.AlgorithmName == "ECGOST3410")
{
- if (_key.PublicKeyParamSet == null)
+ if (priv.PublicKeyParamSet == null)
throw Platform.CreateNotImplementedException("Not a CryptoPro parameter set");
Gost3410PublicKeyAlgParameters gostParams = new Gost3410PublicKeyAlgParameters(
- _key.PublicKeyParamSet, CryptoProObjectIdentifiers.GostR3411x94CryptoProParamSet);
+ priv.PublicKeyParamSet, CryptoProObjectIdentifiers.GostR3411x94CryptoProParamSet);
- algID = new AlgorithmIdentifier(
- CryptoProObjectIdentifiers.GostR3410x2001,
- gostParams.ToAsn1Object());
+ algID = new AlgorithmIdentifier(CryptoProObjectIdentifiers.GostR3410x2001, gostParams);
// TODO Do we need to pass any parameters here?
- ec = new ECPrivateKeyStructure(_key.D);
+ ec = new ECPrivateKeyStructure(orderBitLength, priv.D);
}
else
{
X962Parameters x962;
- if (_key.PublicKeyParamSet == null)
+ if (priv.PublicKeyParamSet == null)
{
- ECDomainParameters kp = _key.Parameters;
- X9ECParameters ecP = new X9ECParameters(kp.Curve, kp.G, kp.N, kp.H, kp.GetSeed());
-
+ X9ECParameters ecP = new X9ECParameters(dp.Curve, dp.G, dp.N, dp.H, dp.GetSeed());
x962 = new X962Parameters(ecP);
}
else
{
- x962 = new X962Parameters(_key.PublicKeyParamSet);
+ x962 = new X962Parameters(priv.PublicKeyParamSet);
}
- Asn1Object x962Object = x962.ToAsn1Object();
-
// TODO Possible to pass the publicKey bitstring here?
- ec = new ECPrivateKeyStructure(_key.D, x962Object);
+ ec = new ECPrivateKeyStructure(orderBitLength, priv.D, x962);
- algID = new AlgorithmIdentifier(X9ObjectIdentifiers.IdECPublicKey, x962Object);
+ algID = new AlgorithmIdentifier(X9ObjectIdentifiers.IdECPublicKey, x962);
}
- return new PrivateKeyInfo(algID, ec.ToAsn1Object());
+ return new PrivateKeyInfo(algID, ec);
}
if (key is Gost3410PrivateKeyParameters)
@@ -176,7 +173,7 @@ namespace Org.BouncyCastle.Pkcs
return new PrivateKeyInfo(algID, new DerOctetString(keyBytes));
}
- throw new ArgumentException("Class provided is not convertible: " + key.GetType().FullName);
+ throw new ArgumentException("Class provided is not convertible: " + Platform.GetTypeName(key));
}
public static PrivateKeyInfo CreatePrivateKeyInfo(
@@ -195,7 +192,7 @@ namespace Org.BouncyCastle.Pkcs
IBufferedCipher cipher = PbeUtilities.CreateEngine(algID) as IBufferedCipher;
if (cipher == null)
- throw new Exception("Unknown encryption algorithm: " + algID.ObjectID);
+ throw new Exception("Unknown encryption algorithm: " + algID.Algorithm);
ICipherParameters cipherParameters = PbeUtilities.GenerateCipherParameters(
algID, passPhrase, wrongPkcs12Zero);
|