summary refs log tree commit diff
path: root/crypto/src/crmf
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/crmf')
-rw-r--r--crypto/src/crmf/AuthenticatorControl.cs10
-rw-r--r--crypto/src/crmf/CertificateRequestMessage.cs40
-rw-r--r--crypto/src/crmf/CertificateRequestMessageBuilder.cs51
-rw-r--r--crypto/src/crmf/CrmfException.cs16
-rw-r--r--crypto/src/crmf/DefaultPKMacPrimitivesProvider.cs7
-rw-r--r--crypto/src/crmf/EncryptedValueBuilder.cs40
-rw-r--r--crypto/src/crmf/IControl.cs2
-rw-r--r--crypto/src/crmf/IEncryptedValuePadder.cs5
-rw-r--r--crypto/src/crmf/IPKMacPrimitivesProvider.cs16
-rw-r--r--crypto/src/crmf/PKMacBuilder.cs76
-rw-r--r--crypto/src/crmf/PkiArchiveControl.cs11
-rw-r--r--crypto/src/crmf/PkiArchiveControlBuilder.cs5
-rw-r--r--crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs10
-rw-r--r--crypto/src/crmf/RegTokenControl.cs11
14 files changed, 121 insertions, 179 deletions
diff --git a/crypto/src/crmf/AuthenticatorControl.cs b/crypto/src/crmf/AuthenticatorControl.cs
index 976135ed8..fc546ede5 100644
--- a/crypto/src/crmf/AuthenticatorControl.cs
+++ b/crypto/src/crmf/AuthenticatorControl.cs
@@ -1,4 +1,5 @@
 using System;
+
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Crmf;
 
@@ -7,9 +8,9 @@ namespace Org.BouncyCastle.Crmf
     /// <summary>
     /// Carrier for an authenticator control.
     /// </summary>
-    public class AuthenticatorControl:IControl
+    public class AuthenticatorControl
+        : IControl
     {
-
         private static readonly DerObjectIdentifier type = CrmfObjectIdentifiers.id_regCtrl_authenticator;
 
         private readonly DerUtf8String token;
@@ -27,7 +28,7 @@ namespace Org.BouncyCastle.Crmf
         /// Basic constructor - build from a string representing the token.
         /// </summary>
         /// <param name="token">string representing the token.</param>
-        public AuthenticatorControl(String token)
+        public AuthenticatorControl(string token)
         {
             this.token = new DerUtf8String(token);
         }
@@ -43,7 +44,8 @@ namespace Org.BouncyCastle.Crmf
         /// <summary>
         /// Return the token associated with this control (a UTF8String).
         /// </summary>
-        public Asn1Encodable Value {
+        public Asn1Encodable Value
+        {
             get { return token; }
         }
     }
diff --git a/crypto/src/crmf/CertificateRequestMessage.cs b/crypto/src/crmf/CertificateRequestMessage.cs
index 5b5d37c9e..c733eecbb 100644
--- a/crypto/src/crmf/CertificateRequestMessage.cs
+++ b/crypto/src/crmf/CertificateRequestMessage.cs
@@ -1,4 +1,5 @@
 using System;
+
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Crmf;
 using Org.BouncyCastle.Crypto;
@@ -16,18 +17,18 @@ namespace Org.BouncyCastle.Crmf
         private readonly CertReqMsg certReqMsg;
         private readonly Controls controls;
 
-        private static CertReqMsg ParseBytes(byte[] encoding)       
-        {        
-                return CertReqMsg.GetInstance(encoding);
+        private static CertReqMsg ParseBytes(byte[] encoding)
+        {
+            return CertReqMsg.GetInstance(encoding);
         }
 
         /// <summary>
         /// Create a CertificateRequestMessage from the passed in bytes.
         /// </summary>
         /// <param name="encoded">BER/DER encoding of the CertReqMsg structure.</param>
-        public CertificateRequestMessage(byte[] encoded):this(CertReqMsg.GetInstance(encoded))
+        public CertificateRequestMessage(byte[] encoded)
+            : this(CertReqMsg.GetInstance(encoded))
         {
-
         }
 
         public CertificateRequestMessage(CertReqMsg certReqMsg)
@@ -42,7 +43,7 @@ namespace Org.BouncyCastle.Crmf
         /// <returns>A CertReqMsg</returns>
         public CertReqMsg ToAsn1Structure()
         {
-            return certReqMsg; 
+            return certReqMsg;
         }
 
         /// <summary>
@@ -70,7 +71,7 @@ namespace Org.BouncyCastle.Crmf
         /// <returns>true if a control value of type is present, false otherwise.</returns>
         public bool HasControl(DerObjectIdentifier objectIdentifier)
         {
-            return findControl(objectIdentifier) != null;
+            return FindControl(objectIdentifier) != null;
         }
 
         /// <summary>
@@ -80,7 +81,7 @@ namespace Org.BouncyCastle.Crmf
         /// <returns>the control value if present, null otherwise.</returns>
         public IControl GetControl(DerObjectIdentifier type)
         {
-            AttributeTypeAndValue found = findControl(type);
+            AttributeTypeAndValue found = FindControl(type);
             if (found != null)
             {
                 if (found.Type.Equals(CrmfObjectIdentifiers.id_regCtrl_pkiArchiveOptions))
@@ -97,14 +98,11 @@ namespace Org.BouncyCastle.Crmf
                 {
                     return new AuthenticatorControl(DerUtf8String.GetInstance(found.Value));
                 }
-            }        
+            }
             return null;
         }
 
-
-
-
-        public AttributeTypeAndValue findControl(DerObjectIdentifier type)
+        public AttributeTypeAndValue FindControl(DerObjectIdentifier type)
         {
             if (controls == null)
             {
@@ -163,9 +161,9 @@ namespace Org.BouncyCastle.Crmf
                 }
 
                 return false;
-
             }
         }
+
         /// <summary>
         /// Return whether or not a signing key proof-of-possession (POP) is valid.
         /// </summary>
@@ -189,8 +187,6 @@ namespace Org.BouncyCastle.Crmf
             throw new InvalidOperationException("not Signing Key type of proof of possession");
         }
 
-
-
         private bool verifySignature(IVerifierFactoryProvider verifierFactoryProvider, PopoSigningKey signKey)
         {
             IVerifierFactory verifer;
@@ -202,22 +198,22 @@ namespace Org.BouncyCastle.Crmf
             }
             catch (Exception ex)
             {
-                throw new CrmfException("unable to create verifier: "+ex.Message, ex);
+                throw new CrmfException("unable to create verifier: " + ex.Message, ex);
             }
 
             if (signKey.PoposkInput != null)
             {
                 byte[] b = signKey.GetDerEncoded();
-              calculator.Stream.Write(b,0,b.Length);
+                calculator.Stream.Write(b, 0, b.Length);
             }
             else
-            {              
+            {
                 byte[] b = certReqMsg.CertReq.GetDerEncoded();
-                calculator.Stream.Write(b,0,b.Length);
+                calculator.Stream.Write(b, 0, b.Length);
             }
 
-            DefaultVerifierResult result = (DefaultVerifierResult) calculator.GetResult();
-      
+            DefaultVerifierResult result = (DefaultVerifierResult)calculator.GetResult();
+
             return result.IsVerified(signKey.Signature.GetBytes());
         }
 
diff --git a/crypto/src/crmf/CertificateRequestMessageBuilder.cs b/crypto/src/crmf/CertificateRequestMessageBuilder.cs
index 9c3cf954d..88d1d87bd 100644
--- a/crypto/src/crmf/CertificateRequestMessageBuilder.cs
+++ b/crypto/src/crmf/CertificateRequestMessageBuilder.cs
@@ -1,14 +1,13 @@
 using System;
 using System.Collections;
-using System.Collections.Generic;
-using System.Security.Cryptography.X509Certificates;
-using System.Text;
+
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Crmf;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Operators;
 using Org.BouncyCastle.Math;
+using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Crmf
 {
@@ -17,7 +16,7 @@ namespace Org.BouncyCastle.Crmf
         private readonly BigInteger _certReqId;
         private X509ExtensionsGenerator _extGenerator;
         private CertTemplateBuilder _templateBuilder;
-        private ArrayList _controls= new ArrayList();
+        private IList _controls = Platform.CreateArrayList();
         private ISignatureFactory _popSigner;
         private PKMacBuilder _pkMacBuilder;
         private char[] _password;
@@ -44,7 +43,6 @@ namespace Org.BouncyCastle.Crmf
             return this;
         }
 
-
         public CertificateRequestMessageBuilder SetIssuer(X509Name issuer)
         {
             if (issuer != null)
@@ -78,13 +76,13 @@ namespace Org.BouncyCastle.Crmf
         public CertificateRequestMessageBuilder SetValidity(Time notBefore, Time notAfter)
         {
             _templateBuilder.SetValidity(new OptionalValidity(notBefore, notAfter));
-            return this;                
+            return this;
         }
 
         public CertificateRequestMessageBuilder AddExtension(DerObjectIdentifier oid, bool critical,
             Asn1Encodable value)
         {
-           _extGenerator.AddExtension(oid,critical, value);
+            _extGenerator.AddExtension(oid, critical, value);
             return this;
         }
 
@@ -109,7 +107,7 @@ namespace Org.BouncyCastle.Crmf
             }
 
             this._popSigner = popoSignatureFactory;
-          
+
             return this;
         }
 
@@ -123,7 +121,6 @@ namespace Org.BouncyCastle.Crmf
             this._popoType = ProofOfPossession.TYPE_KEY_ENCIPHERMENT;
             this._popoPrivKey = new PopoPrivKey(msg);
 
-        
             return this;
         }
 
@@ -142,7 +139,7 @@ namespace Org.BouncyCastle.Crmf
 
             this._popoType = type;
             this._popoPrivKey = new PopoPrivKey(msg);
-            return this;        
+            return this;
         }
 
         public CertificateRequestMessageBuilder SetProofOfPossessionAgreeMac(PKMacValue macValue)
@@ -152,7 +149,7 @@ namespace Org.BouncyCastle.Crmf
                 throw new InvalidOperationException("only one proof of possession allowed");
             }
 
-            this._agreeMac = macValue;        
+            this._agreeMac = macValue;
             return this;
         }
 
@@ -189,35 +186,31 @@ namespace Org.BouncyCastle.Crmf
 
         public CertificateRequestMessage Build()
         {
-            Asn1EncodableVector v = new Asn1EncodableVector();
-
-            v.Add(new DerInteger(this._certReqId));
+            Asn1EncodableVector v = new Asn1EncodableVector(new DerInteger(this._certReqId));
 
             if (!this._extGenerator.IsEmpty)
             {
-               this._templateBuilder.SetExtensions(_extGenerator.Generate());
+                this._templateBuilder.SetExtensions(_extGenerator.Generate());
             }
 
             v.Add(_templateBuilder.Build());
 
-            if (_controls.Count>0)
+            if (_controls.Count > 0)
             {
                 Asn1EncodableVector controlV = new Asn1EncodableVector();
 
-                foreach (Object item  in _controls)
+                foreach (object item in _controls)
                 {
-                    IControl control = (IControl) item;
+                    IControl control = (IControl)item;
                     controlV.Add(new AttributeTypeAndValue(control.Type, control.Value));
                 }
-                    
+
                 v.Add(new DerSequence(controlV));
             }
 
             CertRequest request = CertRequest.GetInstance(new DerSequence(v));
 
-            v = new Asn1EncodableVector();
-
-            v.Add(request);
+            v = new Asn1EncodableVector(request);
 
             if (_popSigner != null)
             {
@@ -226,27 +219,27 @@ namespace Org.BouncyCastle.Crmf
                 if (template.Subject == null || template.PublicKey == null)
                 {
                     SubjectPublicKeyInfo pubKeyInfo = request.CertTemplate.PublicKey;
-                  
+
                     ProofOfPossessionSigningKeyBuilder builder = new ProofOfPossessionSigningKeyBuilder(pubKeyInfo);
 
                     if (_sender != null)
                     {
-                        builder.setSender(_sender);
+                        builder.SetSender(_sender);
                     }
                     else
                     {
-                       // PkMa pkmacGenerator = new PKMACValueGenerator(_pkmacBuilder);
+                        //PKMACValueGenerator pkmacGenerator = new PKMACValueGenerator(_pkmacBuilder);
 
-                        builder.setPublicKeyMac(_pkMacBuilder, _password);
+                        builder.SetPublicKeyMac(_pkMacBuilder, _password);
                     }
 
-                    v.Add(new ProofOfPossession(builder.build(_popSigner)));
+                    v.Add(new ProofOfPossession(builder.Build(_popSigner)));
                 }
                 else
                 {
                     ProofOfPossessionSigningKeyBuilder builder = new ProofOfPossessionSigningKeyBuilder(request);
 
-                    v.Add(new ProofOfPossession(builder.build(_popSigner)));
+                    v.Add(new ProofOfPossession(builder.Build(_popSigner)));
                 }
             }
             else if (_popoPrivKey != null)
@@ -256,7 +249,7 @@ namespace Org.BouncyCastle.Crmf
             else if (_agreeMac != null)
             {
                 v.Add(new ProofOfPossession(ProofOfPossession.TYPE_KEY_AGREEMENT,
-                        PopoPrivKey.GetInstance(new DerTaggedObject(false, PopoPrivKey.agreeMAC, _agreeMac),true )));
+                        PopoPrivKey.GetInstance(new DerTaggedObject(false, PopoPrivKey.agreeMAC, _agreeMac), true)));
 
             }
             else if (_popRaVerified != null)
diff --git a/crypto/src/crmf/CrmfException.cs b/crypto/src/crmf/CrmfException.cs
index c80f480b7..5ae13a0eb 100644
--- a/crypto/src/crmf/CrmfException.cs
+++ b/crypto/src/crmf/CrmfException.cs
@@ -1,25 +1,21 @@
 using System;
-using System.Collections.Generic;
-using System.Runtime.Serialization;
-using System.Text;
 
 namespace Org.BouncyCastle.Crmf
 {
-    public class CrmfException : Exception
+    public class CrmfException
+        : Exception
     {
         public CrmfException()
         {
         }
 
-        public CrmfException(string message) : base(message)
+        public CrmfException(string message)
+            : base(message)
         {
         }
 
-        public CrmfException(string message, Exception innerException) : base(message, innerException)
-        {
-        }
-
-        protected CrmfException(SerializationInfo info, StreamingContext context) : base(info, context)
+        public CrmfException(string message, Exception innerException)
+            : base(message, innerException)
         {
         }
     }
diff --git a/crypto/src/crmf/DefaultPKMacPrimitivesProvider.cs b/crypto/src/crmf/DefaultPKMacPrimitivesProvider.cs
index 1757d6a92..01e196ef4 100644
--- a/crypto/src/crmf/DefaultPKMacPrimitivesProvider.cs
+++ b/crypto/src/crmf/DefaultPKMacPrimitivesProvider.cs
@@ -1,14 +1,13 @@
 using System;
-using System.Collections.Generic;
-using System.Text;
+
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Security;
-using Org.BouncyCastle.Crypto.Parameters;
 
 namespace Org.BouncyCastle.Crmf
 {
-    public class DefaultPKMacPrimitivesProvider : IPKMacPrimitivesProvider
+    public class DefaultPKMacPrimitivesProvider
+        : IPKMacPrimitivesProvider
     {
         public IDigest CreateDigest(AlgorithmIdentifier digestAlg)
         {
diff --git a/crypto/src/crmf/EncryptedValueBuilder.cs b/crypto/src/crmf/EncryptedValueBuilder.cs
index b8076c0e9..8f220330e 100644
--- a/crypto/src/crmf/EncryptedValueBuilder.cs
+++ b/crypto/src/crmf/EncryptedValueBuilder.cs
@@ -1,28 +1,28 @@
 using System;
 using System.Collections;
-using System.Collections.Generic;
+using System.IO;
 using System.Text;
+
+using Org.BouncyCastle.Asn1;
+using Org.BouncyCastle.Asn1.Crmf;
 using Org.BouncyCastle.Asn1.Nist;
+using Org.BouncyCastle.Asn1.Pkcs;
+using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Engines;
 using Org.BouncyCastle.Crypto.Parameters;
-using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Asn1;
-using Org.BouncyCastle.Asn1.Crmf;
-using System.IO;
 using Org.BouncyCastle.Pkcs;
-using Org.BouncyCastle.Asn1.Pkcs;
-using Org.BouncyCastle.X509;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
+using Org.BouncyCastle.X509;
 
 namespace Org.BouncyCastle.Crmf
 {
     public class EncryptedValueBuilder
     {
-        private IKeyWrapper wrapper;
-        private ICipherBuilderWithKey encryptor;
-        private EncryptedValuePadder padder;
+        private readonly IKeyWrapper wrapper;
+        private readonly ICipherBuilderWithKey encryptor;
+        private readonly IEncryptedValuePadder padder;
 
         ///
         /// Create a builder that makes EncryptedValue structures.
@@ -30,7 +30,8 @@ namespace Org.BouncyCastle.Crmf
         /// <param name="wrapper">wrapper a wrapper for key used to encrypt the actual data contained in the EncryptedValue.</param>
         /// <param name="encryptor">encryptor  an output encryptor to encrypt the actual data contained in the EncryptedValue. </param>
         ///
-        public EncryptedValueBuilder(IKeyWrapper wrapper, ICipherBuilderWithKey encryptor) : this(wrapper, encryptor, null)
+        public EncryptedValueBuilder(IKeyWrapper wrapper, ICipherBuilderWithKey encryptor)
+            : this(wrapper, encryptor, null)
         {
         }
 
@@ -41,7 +42,7 @@ namespace Org.BouncyCastle.Crmf
         /// <param name="encryptor">encryptor  an output encryptor to encrypt the actual data contained in the EncryptedValue.</param>
         /// <param name="padder">padder a padder to ensure that the EncryptedValue created will always be a constant length.</param>
         ///
-        public EncryptedValueBuilder(IKeyWrapper wrapper, ICipherBuilderWithKey encryptor, EncryptedValuePadder padder)
+        public EncryptedValueBuilder(IKeyWrapper wrapper, ICipherBuilderWithKey encryptor, IEncryptedValuePadder padder)
         {
             this.wrapper = wrapper;
             this.encryptor = encryptor;
@@ -56,7 +57,7 @@ namespace Org.BouncyCastle.Crmf
         ///
         public EncryptedValue Build(char[] revocationPassphrase)
         {
-            return encryptData(padData(Strings.ToUtf8ByteArray(revocationPassphrase)));
+            return EncryptData(PadData(Strings.ToUtf8ByteArray(revocationPassphrase)));
         }
 
         ///<summary>
@@ -71,7 +72,7 @@ namespace Org.BouncyCastle.Crmf
         {
             try
             {
-                return encryptData(padData(holder.GetEncoded()));
+                return EncryptData(PadData(holder.GetEncoded()));
             }
             catch (IOException e)
             {
@@ -110,19 +111,16 @@ namespace Org.BouncyCastle.Crmf
             {
                 throw new CrmfException("cannot wrap key: " + e.Message, e);
             }
-
         }
 
-        private EncryptedValue encryptData(byte[] data)
+        private EncryptedValue EncryptData(byte[] data)
         {
             MemoryOutputStream bOut = new MemoryOutputStream();
-
             Stream eOut = encryptor.BuildCipher(bOut).Stream;
 
             try
             {
                 eOut.Write(data, 0, data.Length);
-
                 eOut.Close();
             }
             catch (IOException e)
@@ -132,8 +130,8 @@ namespace Org.BouncyCastle.Crmf
 
             AlgorithmIdentifier intendedAlg = null;
             AlgorithmIdentifier symmAlg = (AlgorithmIdentifier)encryptor.AlgorithmDetails;
-            DerBitString encSymmKey;
 
+            DerBitString encSymmKey;
             try
             {
                 encSymmKey = new DerBitString(wrapper.Wrap(((KeyParameter)encryptor.Key).GetKey()).Collect());
@@ -150,7 +148,7 @@ namespace Org.BouncyCastle.Crmf
             return new EncryptedValue(intendedAlg, symmAlg, encSymmKey, keyAlg, valueHint, encValue);
         }
 
-        private byte[] padData(byte[] data)
+        private byte[] PadData(byte[] data)
         {
             if (padder != null)
             {
diff --git a/crypto/src/crmf/IControl.cs b/crypto/src/crmf/IControl.cs
index 14fcc2cd3..9a29ac12a 100644
--- a/crypto/src/crmf/IControl.cs
+++ b/crypto/src/crmf/IControl.cs
@@ -1,8 +1,6 @@
 using System;
 
 using Org.BouncyCastle.Asn1;
-using Org.BouncyCastle.Asn1.Crmf;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Crmf
 {
diff --git a/crypto/src/crmf/IEncryptedValuePadder.cs b/crypto/src/crmf/IEncryptedValuePadder.cs
index b12993e1f..b8986144e 100644
--- a/crypto/src/crmf/IEncryptedValuePadder.cs
+++ b/crypto/src/crmf/IEncryptedValuePadder.cs
@@ -1,15 +1,12 @@
 using System;
-using System.Collections.Generic;
-using System.Text;
 
 namespace Org.BouncyCastle.Crmf
 {
-
      /// <summary>
      /// An encrypted value padder is used to make sure that prior to a value been
      /// encrypted the data is padded to a standard length.
      /// </summary>
-    public interface EncryptedValuePadder
+    public interface IEncryptedValuePadder
     {
         ///
         /// <summary>Return a byte array of padded data.</summary>
diff --git a/crypto/src/crmf/IPKMacPrimitivesProvider.cs b/crypto/src/crmf/IPKMacPrimitivesProvider.cs
index 8b90be515..08f6a624a 100644
--- a/crypto/src/crmf/IPKMacPrimitivesProvider.cs
+++ b/crypto/src/crmf/IPKMacPrimitivesProvider.cs
@@ -1,20 +1,6 @@
 using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using Org.BouncyCastle.Asn1;
-using Org.BouncyCastle.Asn1.Cmp;
-using Org.BouncyCastle.Asn1.Iana;
-using Org.BouncyCastle.Asn1.Nist;
-using Org.BouncyCastle.Asn1.Oiw;
-using Org.BouncyCastle.Asn1.Pkcs;
+
 using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Cms;
-using Org.BouncyCastle.Crypto.IO;
-using Org.BouncyCastle.Crypto.Parameters;
-using Org.BouncyCastle.Security;
-using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Utilities.Encoders;
 using Org.BouncyCastle.Crypto;
 
 namespace Org.BouncyCastle.Crmf
diff --git a/crypto/src/crmf/PKMacBuilder.cs b/crypto/src/crmf/PKMacBuilder.cs
index 00bec9f8b..6741177da 100644
--- a/crypto/src/crmf/PKMacBuilder.cs
+++ b/crypto/src/crmf/PKMacBuilder.cs
@@ -1,30 +1,24 @@
 using System;
-using System.Collections.Generic;
 using System.IO;
-using System.Text;
+
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cmp;
 using Org.BouncyCastle.Asn1.Iana;
-using Org.BouncyCastle.Asn1.Nist;
 using Org.BouncyCastle.Asn1.Oiw;
-using Org.BouncyCastle.Asn1.Pkcs;
 using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Cms;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.IO;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Security;
 using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Utilities.Encoders;
-
 
 namespace Org.BouncyCastle.Crmf
 {
-
-    class PKMacStreamCalculator : IStreamCalculator
+    internal class PKMacStreamCalculator
+        : IStreamCalculator
     {
         private readonly MacSink _stream;
-        
+
         public PKMacStreamCalculator(IMac mac)
         {
             _stream = new MacSink(mac);
@@ -41,17 +35,16 @@ namespace Org.BouncyCastle.Crmf
         }
     }
 
-    class PKMacFactory : IMacFactory
+    internal class PKMacFactory
+        : IMacFactory
     {
         protected readonly PbmParameter parameters;
-        private byte[] key;
-        
-   
+        private readonly byte[] key;
+
         public PKMacFactory(byte[] key, PbmParameter parameters)
         {
             this.key = Arrays.Clone(key);
-
-            this.parameters = parameters;  
+            this.parameters = parameters;
         }
 
         public virtual object AlgorithmDetails
@@ -62,14 +55,13 @@ namespace Org.BouncyCastle.Crmf
         public virtual IStreamCalculator CreateCalculator()
         {
             IMac mac = MacUtilities.GetMac(parameters.Mac.Algorithm);
-
             mac.Init(new KeyParameter(key));
-
             return new PKMacStreamCalculator(mac);
         }
     }
 
-    class DefaultPKMacResult: IBlockResult
+    internal class DefaultPKMacResult
+        : IBlockResult
     {
         private readonly IMac mac;
 
@@ -81,9 +73,7 @@ namespace Org.BouncyCastle.Crmf
         public byte[] Collect()
         {
             byte[] res = new byte[mac.GetMacSize()];
-
             mac.DoFinal(res, 0);
-
             return res;
         }
 
@@ -121,7 +111,7 @@ namespace Org.BouncyCastle.Crmf
         /// <param name="provider"></param>
         public PKMacBuilder(IPKMacPrimitivesProvider provider) :
             this(new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1), 1000, new AlgorithmIdentifier(IanaObjectIdentifiers.HmacSha1, DerNull.Instance), provider)
-        {       
+        {
         }
 
         /// <summary>
@@ -146,7 +136,6 @@ namespace Org.BouncyCastle.Crmf
             this.maxIterations = maxIterations;
         }
 
-
         private PKMacBuilder(AlgorithmIdentifier digestAlgorithmIdentifier, int iterationCount, AlgorithmIdentifier macAlgorithmIdentifier, IPKMacPrimitivesProvider provider)
         {
             this.iterationCount = iterationCount;
@@ -164,9 +153,7 @@ namespace Org.BouncyCastle.Crmf
         public PKMacBuilder SetSaltLength(int saltLength)
         {
             if (saltLength < 8)
-            {
                 throw new ArgumentException("salt length must be at least 8 bytes");
-            }
 
             this.saltLength = saltLength;
 
@@ -182,10 +169,9 @@ namespace Org.BouncyCastle.Crmf
         public PKMacBuilder SetIterationCount(int iterationCount)
         {
             if (iterationCount < 100)
-            {
                 throw new ArgumentException("iteration count must be at least 100");
-            }
-            checkIterationCountCeiling(iterationCount);
+
+            CheckIterationCountCeiling(iterationCount);
 
             this.iterationCount = iterationCount;
 
@@ -199,7 +185,7 @@ namespace Org.BouncyCastle.Crmf
         /// <returns>this</returns>
         public PKMacBuilder SetParameters(PbmParameter parameters)
         {
-            checkIterationCountCeiling(parameters.IterationCount.Value.IntValue);
+            CheckIterationCountCeiling(parameters.IterationCount.Value.IntValue);
 
             this.parameters = parameters;
 
@@ -215,7 +201,7 @@ namespace Org.BouncyCastle.Crmf
         {
             this.random = random;
 
-            return this;          
+            return this;
         }
 
         /// <summary>
@@ -226,33 +212,27 @@ namespace Org.BouncyCastle.Crmf
         public IMacFactory Build(char[] password)
         {
             if (parameters != null)
+                return GenCalculator(parameters, password);
+
+            byte[] salt = new byte[saltLength];
+
+            if (random == null)
             {
-                return genCalculator(parameters, password);
+                this.random = new SecureRandom();
             }
-            else
-            {
-                byte[] salt = new byte[saltLength];
-
-                if (random == null)
-                {
-                    this.random = new SecureRandom();
-                }
 
-                random.NextBytes(salt);
+            random.NextBytes(salt);
 
-                return genCalculator(new PbmParameter(salt, owf, iterationCount, mac), password);
-            }
+            return GenCalculator(new PbmParameter(salt, owf, iterationCount, mac), password);
         }
 
-        private void checkIterationCountCeiling(int iterationCount)
+        private void CheckIterationCountCeiling(int iterationCount)
         {
             if (maxIterations > 0 && iterationCount > maxIterations)
-            {
                 throw new ArgumentException("iteration count exceeds limit (" + iterationCount + " > " + maxIterations + ")");
-            }
         }
 
-        private IMacFactory genCalculator(PbmParameter parameters, char[] password)
+        private IMacFactory GenCalculator(PbmParameter parameters, char[] password)
         {
             // From RFC 4211
             //
@@ -273,8 +253,8 @@ namespace Org.BouncyCastle.Crmf
             byte[] salt = parameters.Salt.GetOctets();
             byte[] K = new byte[pw.Length + salt.Length];
 
-            System.Array.Copy(pw, 0, K, 0, pw.Length);
-            System.Array.Copy(salt, 0, K, pw.Length, salt.Length);
+            Array.Copy(pw, 0, K, 0, pw.Length);
+            Array.Copy(salt, 0, K, pw.Length, salt.Length);
 
             IDigest digest = provider.CreateDigest(parameters.Owf);
 
diff --git a/crypto/src/crmf/PkiArchiveControl.cs b/crypto/src/crmf/PkiArchiveControl.cs
index d533e6c52..251b8db96 100644
--- a/crypto/src/crmf/PkiArchiveControl.cs
+++ b/crypto/src/crmf/PkiArchiveControl.cs
@@ -1,6 +1,5 @@
 using System;
-using System.Collections.Generic;
-using System.Text;
+
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
 using Org.BouncyCastle.Asn1.Crmf;
@@ -8,7 +7,8 @@ using Org.BouncyCastle.Cms;
 
 namespace Org.BouncyCastle.Crmf
 {
-    public class PkiArchiveControl:IControl
+    public class PkiArchiveControl
+        : IControl
     {
         public static readonly int encryptedPrivKey = PkiArchiveOptions.encryptedPrivKey;
         public static readonly int keyGenParameters = PkiArchiveOptions.keyGenParameters;
@@ -33,7 +33,7 @@ namespace Org.BouncyCastle.Crmf
         /// <returns>CRMFObjectIdentifiers.id_regCtrl_pkiArchiveOptions</returns>
         public DerObjectIdentifier Type
         {
-            
+
             get { return type; }
         }
 
@@ -87,9 +87,8 @@ namespace Org.BouncyCastle.Crmf
             }
             catch (Exception e)
             {
-                throw  new CrmfException("CRMF parsing error: "+e.Message, e);
+                throw new CrmfException("CRMF parsing error: " + e.Message, e);
             }
         }
-
     }
 }
diff --git a/crypto/src/crmf/PkiArchiveControlBuilder.cs b/crypto/src/crmf/PkiArchiveControlBuilder.cs
index 2677e4e0d..d79f3b5ed 100644
--- a/crypto/src/crmf/PkiArchiveControlBuilder.cs
+++ b/crypto/src/crmf/PkiArchiveControlBuilder.cs
@@ -1,5 +1,6 @@
 using System;
 using System.IO;
+
 using Org.BouncyCastle.Asn1.Cms;
 using Org.BouncyCastle.Asn1.Crmf;
 using Org.BouncyCastle.Asn1.Pkcs;
@@ -30,7 +31,7 @@ namespace Org.BouncyCastle.Crmf
             }
             catch (IOException e)
             {
-                throw new InvalidOperationException("unable to encode key and general name info");
+                throw new InvalidOperationException("unable to encode key and general name info", e);
             }
 
             this.envGen = new CmsEnvelopedDataGenerator();
@@ -55,4 +56,4 @@ namespace Org.BouncyCastle.Crmf
             return new PkiArchiveControl(new PkiArchiveOptions(new EncryptedKey(envD)));
         }
     }
-}
\ No newline at end of file
+}
diff --git a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs
index 8457585ff..49d10a6bf 100644
--- a/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs
+++ b/crypto/src/crmf/ProofOfPossessionSigningKeyBuilder.cs
@@ -1,12 +1,10 @@
 using System;
-using System.Collections.Generic;
-using System.Text;
+
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Crmf;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Operators;
-using Org.BouncyCastle.Crypto.Paddings;
 
 namespace Org.BouncyCastle.Crmf
 {
@@ -27,14 +25,14 @@ namespace Org.BouncyCastle.Crmf
             this._pubKeyInfo = pubKeyInfo;
         }
 
-        public ProofOfPossessionSigningKeyBuilder setSender(GeneralName name)
+        public ProofOfPossessionSigningKeyBuilder SetSender(GeneralName name)
         {
             this._name = name;
 
             return this;
         }
 
-        public ProofOfPossessionSigningKeyBuilder setPublicKeyMac(PKMacBuilder generator, char[] password)
+        public ProofOfPossessionSigningKeyBuilder SetPublicKeyMac(PKMacBuilder generator, char[] password)
         {
             IMacFactory fact = generator.Build(password);
 
@@ -51,7 +49,7 @@ namespace Org.BouncyCastle.Crmf
             return this;
         }
 
-        public PopoSigningKey build(ISignatureFactory signer)
+        public PopoSigningKey Build(ISignatureFactory signer)
         {
             if (_name != null && _publicKeyMAC != null)
             {
diff --git a/crypto/src/crmf/RegTokenControl.cs b/crypto/src/crmf/RegTokenControl.cs
index 90e956f67..43484097c 100644
--- a/crypto/src/crmf/RegTokenControl.cs
+++ b/crypto/src/crmf/RegTokenControl.cs
@@ -1,17 +1,15 @@
 using System;
-using System.Collections.Generic;
-using System.Text;
 
-using Org.BouncyCastle.Crmf;
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Crmf;
 
 namespace Org.BouncyCastle.Crmf
 {
-    public class RegTokenControl:IControl
+    public class RegTokenControl
+        : IControl
     {
         private static readonly DerObjectIdentifier type = CrmfObjectIdentifiers.id_regCtrl_regToken;
-    
+
         private readonly DerUtf8String token;
 
         /// <summary>
@@ -22,11 +20,12 @@ namespace Org.BouncyCastle.Crmf
         {
             this.token = token;
         }
+
         /// <summary>
         /// Basic constructor - build from a string representing the token.
         /// </summary>
         /// <param name="token">string representing the token.</param>
-        public RegTokenControl(String token)
+        public RegTokenControl(string token)
         {
             this.token = new DerUtf8String(token);
         }