How do I decode a BASE64, PCKS-8 representation of a private key in .net?

后端 未结 1 504
被撕碎了的回忆
被撕碎了的回忆 2021-01-20 17:42

I\'m working on integrating my application with the Walmart Marketplace API. Their documentation pretty much says if you don\'t use Java you\'re on your own. My application

相关标签:
1条回答
  • 2021-01-20 18:14

    it works for me using c# .net 4.6

    using System;
    using System.Security.Cryptography;
    public static string SignData(string stringToBeSigned, string encodedPrivateKey)
            {
                string signedData = string.Empty;
                try
                {
                    var decodeKey = Convert.FromBase64String(privateEncodedStr);
                    var key = CngKey.Import(decodeKey, CngKeyBlobFormat.Pkcs8PrivateBlob);
                    var alg = new RSACng(key);
                    byte[] data = Encoding.UTF8.GetBytes(stringToBeSigned);
                    byte[] signData = alg.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
                    signedData = Convert.ToBase64String(signData);
                }
                catch (Exception)
                {
                    throw;
                }
                return signedData;
            }
    
    0 讨论(0)
提交回复
热议问题