Fork me on GitHub

mono.snk - installation and usage

Gentoo Mono Handbook
How to make signed assembly?
InternalsVisibleTo

Default keys of mono

http://www.mono-project.com/docs/advanced/assemblies-and-the-gac/
PublicKeyToken:
b77a5c561934e089 = ./mcs/class/ecma.pub
b03f5f7f11d50a3a = ./mcs/class/msfinal.pub
0738eb9f132ed756 = ./mcs/class/mono.snk, Mono's PublicKeyToken
35e10195dab3c99f

Getting public key

https://github.com/mono/mono/raw/master/mcs/class/mono.snk
https://github.com/mono/mono/blob/master/mcs/class/mono.snk
sn -tp mono.snk
Mono StrongName - version 4.5.2.0
StrongName utility for signing assemblies
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

Public Key:
002400000480000094000000060200000024000052534131000400000100010079159977d2d03a
8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c
3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fd
dafa277b22de47d6ffea449674a4f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef00
65d016df

Public Key Token: 0738eb9f132ed756


http://stackoverflow.com/questions/29768562/obtain-net-publickeytoken-from-snk-file
Given a byte[] cotnaining the snk file, like

byte[] snk = File.ReadAllBytes("YourSnkFile.snk");

use

byte[] publicKey = GetPublicKey(snk);
byte[] publicKeyToken = GetPublicKeyToken(publicKey);

with these utility methods

public static byte[] GetPublicKey(byte[] snk)
{
    var snkp = new System.Reflection.StrongNameKeyPair(snk);
    byte[] publicKey = snkp.PublicKey;
    return publicKey;
}

public static byte[] GetPublicKeyToken(byte[] publicKey)
{
    using (var csp = new SHA1CryptoServiceProvider())
    {
        byte[] hash = csp.ComputeHash(publicKey);

        byte[] token = new byte[8];

        for (int i = 0; i < 8; i++)
        {
            token[i] = hash[hash.Length - i - 1];
        }

        return token;
    }
}

downloading mono key

wget -c https://github.com/mono/mono/raw/master/mcs/class/mono.snk

add line mirror://gentoo/mono.snk.bz2 to SRC_URI variable:

SRC_URI="${REPOSITORY}/archive/${EGIT_BRANCH}/${EGIT_COMMIT}.zip -> ${PF}.zip
	gac? ( mirror://gentoo/mono.snk.bz2 )"
/var/calculate/remote/distfiles/egit-src/mono-packaging-tools.git/mono.snk

Installation in mono.ebuild

dev-lang/mono/mono-4.9.0.729-r2.ebuild#L64

# sn -i mono.snk mono
Mono StrongName - version 4.9.0.0
StrongName utility for signing assemblies
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.