/// <summary> /// Creates a counter signature, just like /// <c>sn -a IdentityPubKey.snk IdentityKey.snk SignaturePubKey.snk</c> can do. /// The public key <c>sn</c> prints is <paramref name="signaturePubKey"/>'s value. /// </summary> /// <param name="identityPubKey">Identity public key</param> /// <param name="identityKey">Identity strong name key pair</param> /// <param name="signaturePubKey">Signature public key</param> /// <returns>The counter signature</returns> public static byte[] CreateCounterSignature(StrongNamePublicKey identityPubKey, StrongNameKey identityKey, StrongNamePublicKey signaturePubKey) { var hash = AssemblyHash.Hash(signaturePubKey.CreatePublicKey(), identityPubKey.HashAlgorithm); using (var rsa = identityKey.CreateRSA()) { var rsaFmt = new RSAPKCS1SignatureFormatter(rsa); string hashName = identityPubKey.HashAlgorithm.GetName(); rsaFmt.SetHashAlgorithm(hashName); var snSig = rsaFmt.CreateSignature(hash); Array.Reverse(snSig); return(snSig); } }
/// <summary> /// Creates a counter signature, just like /// <c>sn -a IdentityPubKey.snk IdentityKey.snk SignaturePubKey.snk</c> can do. /// The public key <c>sn</c> prints is <paramref name="signaturePubKey"/>'s value. /// </summary> /// <param name="identityPubKey">Identity public key</param> /// <param name="identityKey">Identity strong name key pair</param> /// <param name="signaturePubKey">Signature public key</param> /// <returns>The counter signature as a hex string</returns> public static string CreateCounterSignatureAsString(StrongNamePublicKey identityPubKey, StrongNameKey identityKey, StrongNamePublicKey signaturePubKey) { var counterSignature = CreateCounterSignature(identityPubKey, identityKey, signaturePubKey); return(Utils.ToHex(counterSignature, false)); }