internal ImmutableArray <byte> GetPublicKey(string keyContainer) { IClrStrongName strongName = GetStrongNameInterface(); strongName.StrongNameGetPublicKey(keyContainer, default(IntPtr), 0, out IntPtr keyBlob, out int keyBlobByteCount); byte[] pubKey = new byte[keyBlobByteCount]; Marshal.Copy(keyBlob, pubKey, 0, keyBlobByteCount); strongName.StrongNameFreeBuffer(keyBlob); return(pubKey.AsImmutableOrNull()); }
// internal for testing /// <exception cref="IOException"/> internal ImmutableArray <byte> GetPublicKey(byte[] keyFileContents) { try { var lastSeen = s_lastSeenKeyPair; if (lastSeen != null && ByteSequenceComparer.Equals(lastSeen.Item1, keyFileContents)) { return(lastSeen.Item2); } IClrStrongName strongName = GetStrongNameInterface(); IntPtr keyBlob; int keyBlobByteCount; //EDMAURER use marshal to be safe? unsafe { fixed(byte *p = keyFileContents) { strongName.StrongNameGetPublicKey(null, (IntPtr)p, keyFileContents.Length, out keyBlob, out keyBlobByteCount); } } byte[] pubKey = new byte[keyBlobByteCount]; Marshal.Copy(keyBlob, pubKey, 0, keyBlobByteCount); strongName.StrongNameFreeBuffer(keyBlob); var result = pubKey.AsImmutableOrNull(); s_lastSeenKeyPair = Tuple.Create(keyFileContents, result); return(result); } catch (Exception ex) { throw new IOException(ex.Message); } }