Ejemplo n.º 1
0
        static byte [] CreateStrongName(WriterParameters parameters, byte [] hash)
        {
            const string hash_algo = "SHA1";

            using (var rsa = parameters.CreateRSA()) {
                var formatter = new RSAPKCS1SignatureFormatter(rsa);
                formatter.SetHashAlgorithm(hash_algo);

                byte [] signature = formatter.CreateSignature(hash);
                Array.Reverse(signature);

                return(signature);
            }
        }
Ejemplo n.º 2
0
 public static byte [] GetPublicKey(WriterParameters parameters)
 {
     using (var rsa = parameters.CreateRSA()) {
         var cspBlob   = CryptoConvert.ToCapiPublicKeyBlob(rsa);
         var publicKey = new byte [12 + cspBlob.Length];
         Buffer.BlockCopy(cspBlob, 0, publicKey, 12, cspBlob.Length);
         // The first 12 bytes are documented at:
         // http://msdn.microsoft.com/library/en-us/cprefadd/html/grfungethashfromfile.asp
         // ALG_ID - Signature
         publicKey [1] = 36;
         // ALG_ID - Hash
         publicKey [4] = 4;
         publicKey [5] = 128;
         // Length of Public Key (in bytes)
         publicKey [8]  = (byte)(cspBlob.Length >> 0);
         publicKey [9]  = (byte)(cspBlob.Length >> 8);
         publicKey [10] = (byte)(cspBlob.Length >> 16);
         publicKey [11] = (byte)(cspBlob.Length >> 24);
         return(publicKey);
     }
 }