예제 #1
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);
     }
 }
예제 #2
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)));
        }