-
-
Save jjekson/28251f08d69a549f9276b425b5a6bcec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Security.Cryptography; | |
using System.Security.Cryptography.X509Certificates; | |
| |
public class Program | |
{ | |
public static void Main() | |
{ | |
Certificate Certificate = new Certificate(); | |
byte[] hash = {72, 254, 19, 51, 175, 190, 42, 28, 129, 124, 105, 23, 3, 216, 208, 143, 179, 200, 233, 30}; | |
Console.WriteLine(ToReadableByteArray(Certificate.CreateSignature(hash))); | |
} | |
public static string ToReadableByteArray(byte[] bytes) | |
{ | |
return string.Join(", ", bytes); | |
} | |
} | |
| |
public class Certificate | |
{ | |
private X509Certificate2 pfxCert; | |
public Certificate() | |
{ | |
pfxCert = GetCert(); | |
} | |
private X509Certificate2 GetCert() | |
{ | |
var pfxBase64Encoded = | |
@"MIACAQMwgAYJKoZIhvcNAQcBoIAkgASCBAAwgDCABgkqhkiG9w0BBwGggCSABIIEADCCBa4wggWqBgsqhkiG9w0BDAoBAqCCBO4wggTqMBwGCiqGSIb3DQEMAQMwDgQIqhIuobZGpzcCAgfQBIIEyNZ2cNgMM5C+3t7tQ/c8KCoXmw1lcmPrBTu45btS40iuAMAjN7ssRfUFTFle6/FI6mcyHvyUtgatAAgv+m40jGFMRtA2YFI7oY7J80ok8vnMJlHVdPCzqpm0rXqgDFbeUSVsQUP6JxuNGfgpn9fKaz9k+5DZMvlmFHSE16/8Qb5rIxY6P4AWCBYyvt/YImpH172tK2DTc5xj50Mv3OqSq3CKVY0c/w5ArtfVs/8JFDYR0EzKG1dhFj+fx9vhjm4afRX+K+Wypiw8OkYJ/GjNE/z5/BRqwY8PZEo/t/KCcGMxWPAlOYTnhIxDmlNe6wMgxzDcBGS5gPxbgaouyjA8YVMmgLm4B6rEeTA3rvM68CPQBNuHnhezB/vfiGrPRWiJryvmM3lAMi+L+Iffd6zI7XxhI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seASg8rcBKu5moVCNAQIgzQf9hjKJbkCAgfQAAA="; | |
X509Certificate2 cert = new X509Certificate2(Convert.FromBase64String(pfxBase64Encoded), "Password"); | |
return cert; | |
} | |
| |
// The part which is different in C# and PHP | |
public byte[] CreateSignature(byte[] hash) | |
{ | |
RSAPKCS1SignatureFormatter signatureFormatter = new RSAPKCS1SignatureFormatter(pfxCert.PrivateKey); | |
signatureFormatter.SetHashAlgorithm("SHA1"); | |
return signatureFormatter.CreateSignature(hash); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment