Example #1
0
        public static byte[] ToCapiPublicKeyBlob(RSA rsa)
        {
            RSAParameters rsaparameters = rsa.ExportParameters(false);
            int           num           = rsaparameters.Modulus.Length;

            byte[] array = new byte[20 + num];
            array[0]  = 6;
            array[1]  = 2;
            array[5]  = 36;
            array[8]  = 82;
            array[9]  = 83;
            array[10] = 65;
            array[11] = 49;
            byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
            array[12] = bytesLE[0];
            array[13] = bytesLE[1];
            array[14] = bytesLE[2];
            array[15] = bytesLE[3];
            int num2 = 16;
            int i    = rsaparameters.Exponent.Length;

            while (i > 0)
            {
                array[num2++] = rsaparameters.Exponent[--i];
            }
            num2 = 20;
            byte[] modulus = rsaparameters.Modulus;
            int    num3    = modulus.Length;

            Array.Reverse(modulus, 0, num3);
            Buffer.BlockCopy(modulus, 0, array, num2, num3);
            num2 += num3;
            return(array);
        }
Example #2
0
        public static byte[] ToCapiPublicKeyBlob(DSA dsa)
        {
            DSAParameters dsaParameters = dsa.ExportParameters(false);
            int           length        = dsaParameters.P.Length;

            byte[] numArray = new byte[16 + length + 20 + length + length + 4 + 20];
            numArray[0]  = (byte)6;
            numArray[1]  = (byte)2;
            numArray[5]  = (byte)34;
            numArray[8]  = (byte)68;
            numArray[9]  = (byte)83;
            numArray[10] = (byte)83;
            numArray[11] = (byte)49;
            byte[] bytesLe = CryptoConvert.GetBytesLE(length << 3);
            numArray[12] = bytesLe[0];
            numArray[13] = bytesLe[1];
            numArray[14] = bytesLe[2];
            numArray[15] = bytesLe[3];
            int dstOffset1 = 16;

            byte[] p = dsaParameters.P;
            Array.Reverse((Array)p);
            Buffer.BlockCopy((Array)p, 0, (Array)numArray, dstOffset1, length);
            int dstOffset2 = dstOffset1 + length;

            byte[] q = dsaParameters.Q;
            Array.Reverse((Array)q);
            Buffer.BlockCopy((Array)q, 0, (Array)numArray, dstOffset2, 20);
            int dstOffset3 = dstOffset2 + 20;

            byte[] g = dsaParameters.G;
            Array.Reverse((Array)g);
            Buffer.BlockCopy((Array)g, 0, (Array)numArray, dstOffset3, length);
            int dstOffset4 = dstOffset3 + length;

            byte[] y = dsaParameters.Y;
            Array.Reverse((Array)y);
            Buffer.BlockCopy((Array)y, 0, (Array)numArray, dstOffset4, length);
            int dstOffset5 = dstOffset4 + length;

            Buffer.BlockCopy((Array)CryptoConvert.GetBytesLE(dsaParameters.Counter), 0, (Array)numArray, dstOffset5, 4);
            int dstOffset6 = dstOffset5 + 4;

            byte[] seed = dsaParameters.Seed;
            Array.Reverse((Array)seed);
            Buffer.BlockCopy((Array)seed, 0, (Array)numArray, dstOffset6, 20);
            return(numArray);
        }
Example #3
0
        public static byte[] ToCapiPublicKeyBlob(DSA dsa)
        {
            DSAParameters dsaparameters = dsa.ExportParameters(false);
            int           num           = dsaparameters.P.Length;

            byte[] array = new byte[16 + num + 20 + num + num + 4 + 20];
            array[0]  = 6;
            array[1]  = 2;
            array[5]  = 34;
            array[8]  = 68;
            array[9]  = 83;
            array[10] = 83;
            array[11] = 49;
            byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
            array[12] = bytesLE[0];
            array[13] = bytesLE[1];
            array[14] = bytesLE[2];
            array[15] = bytesLE[3];
            int num2 = 16;

            byte[] array2 = dsaparameters.P;
            Array.Reverse(array2);
            Buffer.BlockCopy(array2, 0, array, num2, num);
            num2  += num;
            array2 = dsaparameters.Q;
            Array.Reverse(array2);
            Buffer.BlockCopy(array2, 0, array, num2, 20);
            num2  += 20;
            array2 = dsaparameters.G;
            Array.Reverse(array2);
            Buffer.BlockCopy(array2, 0, array, num2, num);
            num2  += num;
            array2 = dsaparameters.Y;
            Array.Reverse(array2);
            Buffer.BlockCopy(array2, 0, array, num2, num);
            num2 += num;
            Buffer.BlockCopy(CryptoConvert.GetBytesLE(dsaparameters.Counter), 0, array, num2, 4);
            num2  += 4;
            array2 = dsaparameters.Seed;
            Array.Reverse(array2);
            Buffer.BlockCopy(array2, 0, array, num2, 20);
            return(array);
        }
Example #4
0
        public static byte[] ToCapiPublicKeyBlob(RSA rsa)
        {
            RSAParameters rsaParameters = rsa.ExportParameters(false);
            int           length1       = rsaParameters.Modulus.Length;

            byte[] numArray = new byte[20 + length1];
            numArray[0]  = (byte)6;
            numArray[1]  = (byte)2;
            numArray[5]  = (byte)36;
            numArray[8]  = (byte)82;
            numArray[9]  = (byte)83;
            numArray[10] = (byte)65;
            numArray[11] = (byte)49;
            byte[] bytesLe = CryptoConvert.GetBytesLE(length1 << 3);
            numArray[12] = bytesLe[0];
            numArray[13] = bytesLe[1];
            numArray[14] = bytesLe[2];
            numArray[15] = bytesLe[3];
            int num1    = 16;
            int length2 = rsaParameters.Exponent.Length;

            while (length2 > 0)
            {
                numArray[num1++] = rsaParameters.Exponent[--length2];
            }
            int dstOffset = 20;

            byte[] modulus = rsaParameters.Modulus;
            int    length3 = modulus.Length;

            Array.Reverse((Array)modulus, 0, length3);
            Buffer.BlockCopy((Array)modulus, 0, (Array)numArray, dstOffset, length3);
            int num2 = dstOffset + length3;

            return(numArray);
        }
Example #5
0
        public static byte[] ToCapiPrivateKeyBlob(RSA rsa)
        {
            RSAParameters rsaparameters = rsa.ExportParameters(true);
            int           num           = rsaparameters.Modulus.Length;

            byte[] array = new byte[20 + (num << 2) + (num >> 1)];
            array[0]  = 7;
            array[1]  = 2;
            array[5]  = 36;
            array[8]  = 82;
            array[9]  = 83;
            array[10] = 65;
            array[11] = 50;
            byte[] bytesLE = CryptoConvert.GetBytesLE(num << 3);
            array[12] = bytesLE[0];
            array[13] = bytesLE[1];
            array[14] = bytesLE[2];
            array[15] = bytesLE[3];
            int num2 = 16;
            int i    = rsaparameters.Exponent.Length;

            while (i > 0)
            {
                array[num2++] = rsaparameters.Exponent[--i];
            }
            num2 = 20;
            byte[] array2 = rsaparameters.Modulus;
            int    num3   = array2.Length;

            Array.Reverse(array2, 0, num3);
            Buffer.BlockCopy(array2, 0, array, num2, num3);
            num2  += num3;
            array2 = rsaparameters.P;
            num3   = array2.Length;
            Array.Reverse(array2, 0, num3);
            Buffer.BlockCopy(array2, 0, array, num2, num3);
            num2  += num3;
            array2 = rsaparameters.Q;
            num3   = array2.Length;
            Array.Reverse(array2, 0, num3);
            Buffer.BlockCopy(array2, 0, array, num2, num3);
            num2  += num3;
            array2 = rsaparameters.DP;
            num3   = array2.Length;
            Array.Reverse(array2, 0, num3);
            Buffer.BlockCopy(array2, 0, array, num2, num3);
            num2  += num3;
            array2 = rsaparameters.DQ;
            num3   = array2.Length;
            Array.Reverse(array2, 0, num3);
            Buffer.BlockCopy(array2, 0, array, num2, num3);
            num2  += num3;
            array2 = rsaparameters.InverseQ;
            num3   = array2.Length;
            Array.Reverse(array2, 0, num3);
            Buffer.BlockCopy(array2, 0, array, num2, num3);
            num2  += num3;
            array2 = rsaparameters.D;
            num3   = array2.Length;
            Array.Reverse(array2, 0, num3);
            Buffer.BlockCopy(array2, 0, array, num2, num3);
            return(array);
        }
Example #6
0
        public static byte[] ToCapiPrivateKeyBlob(RSA rsa)
        {
            RSAParameters rsaParameters = rsa.ExportParameters(true);
            int           length1       = rsaParameters.Modulus.Length;

            byte[] numArray = new byte[20 + (length1 << 2) + (length1 >> 1)];
            numArray[0]  = (byte)7;
            numArray[1]  = (byte)2;
            numArray[5]  = (byte)36;
            numArray[8]  = (byte)82;
            numArray[9]  = (byte)83;
            numArray[10] = (byte)65;
            numArray[11] = (byte)50;
            byte[] bytesLe = CryptoConvert.GetBytesLE(length1 << 3);
            numArray[12] = bytesLe[0];
            numArray[13] = bytesLe[1];
            numArray[14] = bytesLe[2];
            numArray[15] = bytesLe[3];
            int num     = 16;
            int length2 = rsaParameters.Exponent.Length;

            while (length2 > 0)
            {
                numArray[num++] = rsaParameters.Exponent[--length2];
            }
            int dstOffset1 = 20;

            byte[] modulus = rsaParameters.Modulus;
            int    length3 = modulus.Length;

            Array.Reverse((Array)modulus, 0, length3);
            Buffer.BlockCopy((Array)modulus, 0, (Array)numArray, dstOffset1, length3);
            int dstOffset2 = dstOffset1 + length3;

            byte[] p       = rsaParameters.P;
            int    length4 = p.Length;

            Array.Reverse((Array)p, 0, length4);
            Buffer.BlockCopy((Array)p, 0, (Array)numArray, dstOffset2, length4);
            int dstOffset3 = dstOffset2 + length4;

            byte[] q       = rsaParameters.Q;
            int    length5 = q.Length;

            Array.Reverse((Array)q, 0, length5);
            Buffer.BlockCopy((Array)q, 0, (Array)numArray, dstOffset3, length5);
            int dstOffset4 = dstOffset3 + length5;

            byte[] dp      = rsaParameters.DP;
            int    length6 = dp.Length;

            Array.Reverse((Array)dp, 0, length6);
            Buffer.BlockCopy((Array)dp, 0, (Array)numArray, dstOffset4, length6);
            int dstOffset5 = dstOffset4 + length6;

            byte[] dq      = rsaParameters.DQ;
            int    length7 = dq.Length;

            Array.Reverse((Array)dq, 0, length7);
            Buffer.BlockCopy((Array)dq, 0, (Array)numArray, dstOffset5, length7);
            int dstOffset6 = dstOffset5 + length7;

            byte[] inverseQ = rsaParameters.InverseQ;
            int    length8  = inverseQ.Length;

            Array.Reverse((Array)inverseQ, 0, length8);
            Buffer.BlockCopy((Array)inverseQ, 0, (Array)numArray, dstOffset6, length8);
            int dstOffset7 = dstOffset6 + length8;

            byte[] d       = rsaParameters.D;
            int    length9 = d.Length;

            Array.Reverse((Array)d, 0, length9);
            Buffer.BlockCopy((Array)d, 0, (Array)numArray, dstOffset7, length9);
            return(numArray);
        }