Not alabilirsiniz SHA 256. desteklemiyor olmasıdır Sonsuza kadar beni anlamaya ve neredeyse her şeyi denedim. Bana bağlantı sağlayan kod parçasının bağlantısını yayınlamak için Gonzalo Gallotti'ye gidiyorum. Her adımın ne yaptığını göstermek için kodumu yorumladım. NOT: Bu kod kod örneği aşağıda nakledilir düzgün oluşturulan belgesi olmayan çalışmaz:
public void GetCertificate() {
// Get the Machine Cert Store
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
string alg = CryptoConfig.MapNameToOID("SHA512");
// Open the cert store
store.Open(OpenFlags.ReadWrite);
// Loop through each certificate within the store
foreach (X509Certificate2 myCert in store.Certificates)
{
// Get the certificate we are looking for
if (myCert.IssuerName.Name.Contains("CN=YourSite"))
{
// Check if the certificate has a private key
if (myCert.HasPrivateKey)
{
// Get your custom signature as a string
string mySignature = GetSignatureString();
// Convert signature to byte array
byte[] originalData = Encoding.UTF8.GetBytes(mySignature);
// Create RSA provider from private key
RSACryptoServiceProvider rsaProvider = (RSACryptoServiceProvider)myCert.PrivateKey;
// Sign the signature with SHA512
byte[] signedSignature = signedSignature = rsaProvider.SignData(originalData, alg);
if (rsaProvider.VerifyData(originalData, alg, signedSignature))
{
// Signature is verified Do Stuff
}
else
{
throw new Exception("The data does not match the signature.");
}
}
}
}
}
Sonraki - Sertifika SHA512 olmak ve SHA512 Yetenekli olduğuna dair bir CSP (Şifreleme Servis Sağlayıcısı) kullanmak zorundadır. İşte CSP'lerin ve yeteneklerinin bir listesi. SHA512'yi ararsanız, "Microsoft Enhanced RSA ve AES Şifreleme Sağlayıcısı" nı bulacaksınız. Varsayılan olarak sertifika üretme bunu kullanmaz (en azından Windows'ta), böylece sertifikayı oluştururken belirtmeniz gerekir.
özel anahtarı ve sertifikayı oluşturun - bu adım size sorular soracaktır, eyalet, bölge vs vs
openssl req -x509 -nodes -sha512 -newkey rsa:2048 -keyout 512key.pem -out 512cert.pem -days 3650
Microsoft Gelişmiş RSA ve AES Şifreleme Sağlayıcısı kullanarak sertifika deposuna almak için PFX dosyası oluşturun:
openssl pkcs12 –export –in 512cert.pem –inkey 512key.pem –CSP “Microsoft Enhanced RSA and AES Cryptographic Provider” –out 512pfx.pfx
"id" değeri nedir? – dtb
Soruyu, id değeriyle güncelledim. – scott