コード例 #1
0
        public void Sign(string path, bool strongName = false)
        {
            var certRef = new CertificateReference(Certificate);
            var r = BinaryLoad(path);

            r.SigningCertificate = certRef;
            if (strongName)
                r.StrongNameKeyCertificate = certRef;

            r.Save().Wait();
        }
コード例 #2
0
ファイル: PeBinary.cs プロジェクト: zellus/coapp.powershell
        /// <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);
        }
コード例 #3
0
ファイル: PeBinary.cs プロジェクト: zellus/coapp.powershell
 public static void SignFile(string filename, CertificateReference certificate)
 {
     SignFile(filename, certificate.Certificate);
 }
コード例 #4
0
ファイル: PeBinary.cs プロジェクト: roomaroo/coapp.powershell
 public static void SignFile(string filename, CertificateReference certificate) {
     SignFile(filename, certificate.Certificate);
 }
コード例 #5
0
ファイル: PeBinary.cs プロジェクト: roomaroo/coapp.powershell
        /// <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);
        }