Example #1
0
 private static void checkKeyBlob(byte[] putativeKeyBlob)
 {
     if (!RsaKeyBlob.isValidKeyBlob(putativeKeyBlob))
     {
         throw new CryptographicException("RSA key blob data is corrupted");
     }
 }
Example #2
0
 public void Dispose()
 {
     this.m_bitLength = 0;
     RsaKeyBlob.clearArray(ref this.m_D);
     RsaKeyBlob.clearArray(ref this.m_DP);
     RsaKeyBlob.clearArray(ref this.m_DQ);
     RsaKeyBlob.clearArray(ref this.m_exponent);
     RsaKeyBlob.clearArray(ref this.m_inverseQ);
     this.m_isPrivateKey = false;
     RsaKeyBlob.clearArray(ref this.m_keyBlob);
     RsaKeyBlob.clearArray(ref this.m_modulus);
     RsaKeyBlob.clearArray(ref this.m_P);
     RsaKeyBlob.clearArray(ref this.m_Q);
     GC.SuppressFinalize(this);
 }
Example #3
0
        public void Init(byte[] keyBlob)
        {
            RSAParameters parameters = default(RSAParameters);
            RsaKeyBlob    rsaKeyBlob = new RsaKeyBlob(keyBlob);

            try
            {
                parameters = RsaCapiKey.CreateRsaParameters(rsaKeyBlob);
                this.m_provider.ImportParameters(parameters);
            }
            finally
            {
                RsaCapiKey.ClearRsaParameters(parameters);
                rsaKeyBlob.Dispose();
            }
        }
Example #4
0
        private static RSAParameters CreateRsaParameters(RsaKeyBlob keyBlob)
        {
            RSAParameters result = default(RSAParameters);

            result.Modulus  = ByteArrayUtilities.CreateReversedArray(keyBlob.Modulus);
            result.Exponent = ByteArrayUtilities.CreateReversedArray(keyBlob.Exponent);
            if (keyBlob.IsPrivateKey)
            {
                result.D        = ByteArrayUtilities.CreateReversedArray(keyBlob.D);
                result.DP       = ByteArrayUtilities.CreateReversedArray(keyBlob.DP);
                result.DQ       = ByteArrayUtilities.CreateReversedArray(keyBlob.DQ);
                result.InverseQ = ByteArrayUtilities.CreateReversedArray(keyBlob.InverseQ);
                result.P        = ByteArrayUtilities.CreateReversedArray(keyBlob.P);
                result.Q        = ByteArrayUtilities.CreateReversedArray(keyBlob.Q);
            }
            return(result);
        }
Example #5
0
 private void init(byte[] keyBlob)
 {
     if (keyBlob == null)
     {
         throw new ArgumentException("InvalidKeyBlob", "keyBlob");
     }
     if (RsaKeyBlob.isValidKeyBlob(keyBlob))
     {
         this.m_keyBlob = (byte[])keyBlob.Clone();
     }
     else
     {
         if (keyBlob.Length <= 12)
         {
             throw new CryptographicException("Key blob is invalid");
         }
         this.m_keyBlob = new byte[keyBlob.Length - 12];
         Array.Copy(keyBlob, 12, this.m_keyBlob, 0, this.m_keyBlob.Length);
     }
     RsaKeyBlob.checkKeyBlob(this.m_keyBlob);
     if (keyBlob[0] == 7)
     {
         this.m_bitLength    = RsaKeyBlob.getPrivateKeyLength(this.m_keyBlob.Length);
         this.m_isPrivateKey = true;
     }
     else
     {
         this.m_bitLength    = RsaKeyBlob.getPublicKeyLength(this.m_keyBlob.Length);
         this.m_isPrivateKey = false;
     }
     this.m_modulus = new byte[this.m_bitLength / 8];
     Array.Copy(this.m_keyBlob, 20, this.m_modulus, 0, this.m_modulus.Length);
     this.m_exponent = new byte[4];
     Array.Copy(this.m_keyBlob, 16, this.m_exponent, 0, this.m_exponent.Length);
     if (this.m_isPrivateKey)
     {
         int num = 20 + this.m_modulus.Length;
         RsaKeyBlob.assignPrivateKeyValue(this.m_keyBlob, ref num, out this.m_P, this.m_modulus.Length / 2);
         RsaKeyBlob.assignPrivateKeyValue(this.m_keyBlob, ref num, out this.m_Q, this.m_modulus.Length / 2);
         RsaKeyBlob.assignPrivateKeyValue(this.m_keyBlob, ref num, out this.m_DP, this.m_modulus.Length / 2);
         RsaKeyBlob.assignPrivateKeyValue(this.m_keyBlob, ref num, out this.m_DQ, this.m_modulus.Length / 2);
         RsaKeyBlob.assignPrivateKeyValue(this.m_keyBlob, ref num, out this.m_inverseQ, this.m_modulus.Length / 2);
         RsaKeyBlob.assignPrivateKeyValue(this.m_keyBlob, ref num, out this.m_D, this.m_modulus.Length);
     }
 }
Example #6
0
        private static bool isValidKeyBlob(byte[] putativeKeyBlob)
        {
            bool flag = RsaKeyBlob.isValuePresent(putativeKeyBlob, 0, 1, new int[]
            {
                6
            });
            int num = (int)BitConverter.ToUInt32(putativeKeyBlob, 12);

            return(RsaKeyBlob.isValuePresent(putativeKeyBlob, 0, 1, new int[]
            {
                flag ? 6 : 7
            }) && RsaKeyBlob.isValuePresent(putativeKeyBlob, 4, 2, new int[]
            {
                41984,
                9216
            }) && RsaKeyBlob.isValuePresent(putativeKeyBlob, 8, 4, new int[]
            {
                flag ? 826364754 : 843141970
            }) && num == (flag ? RsaKeyBlob.getPublicKeyLength(putativeKeyBlob.Length) : RsaKeyBlob.getPrivateKeyLength(putativeKeyBlob.Length)));
        }