Ejemplo n.º 1
0
        internal static RSAParameters CreateSigningInformationFromKeyBLOB(Byte[] blob, AssemblyHashAlgorithm?signingAlgorithm, out Byte[] publicKey, out AssemblyHashAlgorithm actualSigningAlgorithm)
        {
            // There might be actual key after a header, if first byte is zero.
            var   hasHeader = blob[0] == 0x00;
            Int32 pkLen, algID;
            var   retVal = CreateRSAParametersFromCapiBLOB(blob, hasHeader ? CAPI_HEADER_SIZE : 0, out pkLen, out algID);

            publicKey = new Byte[pkLen + CAPI_HEADER_SIZE];
            var idx = 0;

            if (hasHeader)
            {
                // Just copy from blob
                publicKey.BlockCopyFrom(ref idx, blob, 0, publicKey.Length);
                idx = 4;
                if (signingAlgorithm.HasValue)
                {
                    actualSigningAlgorithm = signingAlgorithm.Value;
                    publicKey.WriteInt32LEToBytes(ref idx, (Int32)actualSigningAlgorithm);
                }
                else
                {
                    actualSigningAlgorithm = (AssemblyHashAlgorithm)publicKey.ReadInt32LEFromBytes(ref idx);
                }
            }
            else
            {
                // Write public key, including header
                // Write header explicitly. ALG-ID, followed by AssemblyHashAlgorithmID, followed by the size of the PK
                actualSigningAlgorithm = signingAlgorithm ?? AssemblyHashAlgorithm.SHA1;// Defaults to SHA1
                publicKey
                .WriteInt32LEToBytes(ref idx, algID)
                .WriteInt32LEToBytes(ref idx, (Int32)actualSigningAlgorithm)
                .WriteInt32LEToBytes(ref idx, pkLen)
                .BlockCopyFrom(ref idx, blob, 0, pkLen);
            }
            // Mark PK actually being PK
            publicKey[CAPI_HEADER_SIZE] = PUBLIC_KEY;

            // Set public key algorithm to RSA1
            idx = 20;
            publicKey.WriteUInt32LEToBytes(ref idx, RSA1);

            return(retVal);
        }