Example #1
0
        /*  leave this out for now. We'll make the command line compilers have this behavior, but
         * not the compiler library. This differs from previous versions because specifying a keyfile
         * and container through either the command line or attributes gave this "install the key" behavior.
         *
         *
         * //EDMAURER alink had weird, MSDN spec'd behavior. from MSDN "In case both /keyfile and /keycontainer are
         * //specified (either by command-line option or by custom attribute) in the same compilation, the compiler
         * //first tries the key container. If that succeeds, then the assembly is signed with the information in the
         * //key container. If the compiler does not find the key container, it tries the file specified with /keyfile.
         * //If this succeeds, the assembly is signed with the information in the key file, and the key information is
         * //installed in the key container (similar to sn -i) so that on the next compilation, the key container will
         * //be valid.
         *
         * private static ImmutableArray<byte> GetPublicKeyAndPossiblyInstall(string keyFilename, string keyContainer)
         * {
         *  if (keyContainer != null)
         *  {
         *      ImmutableArray<byte> result = GetPublicKey(keyContainer);
         *
         *      if (result.IsNotNull)
         *          return result;
         *  }
         *
         *  if (keyFilename != null)
         *  {
         *      byte[] keyFileContents = System.IO.File.ReadAllBytes(keyFilename);
         *
         *      if (keyContainer != null)
         *          InstallKey(keyFileContents, keyFilename);
         *
         *      return GetPublicKey(keyFileContents);
         *  }
         *
         *  return default(ImmutableArray<byte>);
         * }
         */

        /// <exception cref="IOException"/>
        private static void Sign(string filePath, string keyName)
        {
            try
            {
                ICLRStrongName strongName = GetStrongNameInterface();

                int unused;
                strongName.StrongNameSignatureGeneration(filePath, keyName, IntPtr.Zero, 0, null, out unused);
            }
            catch (COMException ex)
            {
                throw new IOException(ex.Message, ex);
            }
        }
Example #2
0
        /// <exception cref="IOException"/>
        private static void Sign(string filePath, ImmutableArray <byte> keyPair)
        {
            try
            {
                ICLRStrongName strongName = GetStrongNameInterface();

                using (var pinned = PinnedImmutableArray.Create(keyPair))
                {
                    int unused;
                    strongName.StrongNameSignatureGeneration(filePath, null, pinned.Pointer, keyPair.Length, null, out unused);
                }
            }
            catch (COMException ex)
            {
                throw new IOException(ex.Message, ex);
            }
        }
        /// <exception cref="IOException"/>
        private static unsafe void Sign(string filePath, ImmutableArray <byte> keyPair)
        {
            try
            {
                ICLRStrongName strongName = GetStrongNameInterface();

                fixed(byte *pinned = keyPair.ToArray())
                {
                    int unused;

                    strongName.StrongNameSignatureGeneration(filePath, null, (IntPtr)pinned, keyPair.Length, null, out unused);
                }
            }
            catch (COMException ex)
            {
                throw new IOException(ex.Message, ex);
            }
        }