Exemple #1
0
 public void Sign(string fileName)
 {
     if (!Mscoree.StrongNameSignatureGeneration(fileName, _keyContainer, IntPtr.Zero, 0, 0, 0))
     {
         throw new ClrPlusException(String.Format("Unable Strong name assembly '{0}'.", fileName));
     }
 }
Exemple #2
0
        /// <summary>
        ///     This puts the strong name into the actual file on disk. The file MUST be delay signed by this point.
        /// </summary>
        /// <param name="filename"> </param>
        /// <param name="certificate"> </param>
        public static void ApplyStrongName(string filename, CertificateReference certificate)
        {
            filename = filename.GetFullPath();
            filename.TryHardToMakeFileWriteable();

            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("Can't find file", filename);
            }

            // strong name the binary using the private key from the certificate.
            var wszKeyContainer = Guid.NewGuid().ToString();
            var privateKey      = (certificate.Certificate.PrivateKey as RSACryptoServiceProvider).ExportCspBlob(true);

            if (!Mscoree.StrongNameKeyInstall(wszKeyContainer, privateKey, privateKey.Length))
            {
                throw new ClrPlusException("Unable to create KeyContainer");
            }
            if (!Mscoree.StrongNameSignatureGeneration(filename, wszKeyContainer, IntPtr.Zero, 0, 0, 0))
            {
                throw new ClrPlusException("Unable Strong name assembly '{0}'.".format(filename));
            }
            Mscoree.StrongNameKeyDelete(wszKeyContainer);
        }