BouncyCastle update.

git-svn-id: svn://svn.code.sf.net/p/itextsharp/code/trunk@6 820d3149-562b-4f88-9aa4-a8e61a3485cf
master
psoares33 2008-07-20 18:40:16 +00:00
parent ee29289cb4
commit b5c4ee7a7b
6 changed files with 125 additions and 72 deletions

View File

@ -70,12 +70,27 @@ namespace Org.BouncyCastle.Asn1.Pkcs
get { return iterationCount; }
}
/**
* <pre>
* MacData ::= SEQUENCE {
* mac DigestInfo,
* macSalt OCTET STRING,
* iterations INTEGER DEFAULT 1
* -- Note: The default is for historic reasons and its use is deprecated. A
* -- higher value, like 1024 is recommended.
* </pre>
* @return the basic DERObject construction.
*/
public override Asn1Object ToAsn1Object()
{
return new DerSequence(
digInfo,
new DerOctetString(salt),
new DerInteger(iterationCount));
Asn1EncodableVector v = new Asn1EncodableVector(digInfo, new DerOctetString(salt));
if (!iterationCount.Equals(BigInteger.One))
{
v.Add(new DerInteger(iterationCount));
}
return new DerSequence(v);
}
}
}

View File

@ -8,6 +8,22 @@ namespace Org.BouncyCastle.Asn1.X509
{
private Asn1Sequence permitted, excluded;
public static NameConstraints GetInstance(
object obj)
{
if (obj == null || obj is NameConstraints)
{
return (NameConstraints) obj;
}
if (obj is Asn1Sequence)
{
return new NameConstraints((Asn1Sequence) obj);
}
throw new ArgumentException("unknown object in factory: " + obj.GetType().Name, "obj");
}
public NameConstraints(
Asn1Sequence seq)
{

View File

@ -73,7 +73,11 @@ namespace Org.BouncyCastle.Asn1.X509
{
buffer.Append('\\');
}
buffer.Append(c);
else if (c == '+' && separator != '+')
{
buffer.Append('\\');
}
buffer.Append(c);
escaped = false;
}
else if (c == '\\')

View File

@ -8,7 +8,6 @@ using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Security.Certificates;
using Org.BouncyCastle.X509;
namespace Org.BouncyCastle.Ocsp
@ -268,7 +267,7 @@ namespace Org.BouncyCastle.Ocsp
{
throw new OcspException("error processing certs", e);
}
catch (CertificateEncodingException e)
catch (Security.Certificates.CertificateEncodingException e)
{
throw new OcspException("error encoding certs", e);
}

View File

@ -71,74 +71,22 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
get { return keyData.KeyId; }
}
/// <summary>
/// Return the algorithm code for the symmetric algorithm used to encrypt the data.
/// </summary>
public SymmetricKeyAlgorithmTag GetSymmetricAlgorithm(
PgpPrivateKey privKey)
{
byte[] plain = fetchSymmetricKeyData(privKey);
return (SymmetricKeyAlgorithmTag) plain[0];
}
/// <summary>Return the decrypted data stream for the packet.</summary>
public Stream GetDataStream(
PgpPrivateKey privKey)
{
IBufferedCipher c1 = GetKeyCipher(keyData.Algorithm);
try
{
c1.Init(false, privKey.Key);
}
catch (InvalidKeyException e)
{
throw new PgpException("error setting asymmetric cipher", e);
}
BigInteger[] keyD = keyData.GetEncSessionKey();
if (keyData.Algorithm == PublicKeyAlgorithmTag.RsaEncrypt
|| keyData.Algorithm == PublicKeyAlgorithmTag.RsaGeneral)
{
c1.ProcessBytes(keyD[0].ToByteArrayUnsigned());
}
else
{
ElGamalPrivateKeyParameters k = (ElGamalPrivateKeyParameters)privKey.Key;
int size = (k.Parameters.P.BitLength + 7) / 8;
byte[] bi = keyD[0].ToByteArray();
int diff = bi.Length - size;
if (diff >= 0)
{
c1.ProcessBytes(bi, diff, size);
}
else
{
byte[] zeros = new byte[-diff];
c1.ProcessBytes(zeros);
c1.ProcessBytes(bi);
}
bi = keyD[1].ToByteArray();
diff = bi.Length - size;
if (diff >= 0)
{
c1.ProcessBytes(bi, diff, size);
}
else
{
byte[] zeros = new byte[-diff];
c1.ProcessBytes(zeros);
c1.ProcessBytes(bi);
}
}
byte[] plain;
try
{
plain = c1.DoFinal();
}
catch (Exception e)
{
throw new PgpException("exception decrypting secret key", e);
}
if (!ConfirmCheckSum(plain))
throw new PgpKeyValidationException("key checksum failed");
byte[] plain = fetchSymmetricKeyData(privKey);
IBufferedCipher c2;
string cipherName = PgpUtilities.GetSymmetricCipherName((SymmetricKeyAlgorithmTag) plain[0]);
@ -229,5 +177,76 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
throw new PgpException("Exception starting decryption", e);
}
}
private byte[] fetchSymmetricKeyData(
PgpPrivateKey privKey)
{
IBufferedCipher c1 = GetKeyCipher(keyData.Algorithm);
try
{
c1.Init(false, privKey.Key);
}
catch (InvalidKeyException e)
{
throw new PgpException("error setting asymmetric cipher", e);
}
BigInteger[] keyD = keyData.GetEncSessionKey();
if (keyData.Algorithm == PublicKeyAlgorithmTag.RsaEncrypt
|| keyData.Algorithm == PublicKeyAlgorithmTag.RsaGeneral)
{
c1.ProcessBytes(keyD[0].ToByteArrayUnsigned());
}
else
{
ElGamalPrivateKeyParameters k = (ElGamalPrivateKeyParameters)privKey.Key;
int size = (k.Parameters.P.BitLength + 7) / 8;
byte[] bi = keyD[0].ToByteArray();
int diff = bi.Length - size;
if (diff >= 0)
{
c1.ProcessBytes(bi, diff, size);
}
else
{
byte[] zeros = new byte[-diff];
c1.ProcessBytes(zeros);
c1.ProcessBytes(bi);
}
bi = keyD[1].ToByteArray();
diff = bi.Length - size;
if (diff >= 0)
{
c1.ProcessBytes(bi, diff, size);
}
else
{
byte[] zeros = new byte[-diff];
c1.ProcessBytes(zeros);
c1.ProcessBytes(bi);
}
}
byte[] plain;
try
{
plain = c1.DoFinal();
}
catch (Exception e)
{
throw new PgpException("exception decrypting secret key", e);
}
if (!ConfirmCheckSum(plain))
throw new PgpKeyValidationException("key checksum failed");
return plain;
}
}
}

View File

@ -22,7 +22,7 @@ namespace Org.BouncyCastle.X509
*
* @param issuer The issuer
*/
internal AttributeCertificateIssuer(
public AttributeCertificateIssuer(
AttCertIssuer issuer)
{
form = issuer.Issuer;