public string GenerateSignature(string compactJson, string method, string nonceStr, string privateKey, string requestUrl, string signType, string timestamp, string environment)
        {
            string signedData = "";

            try
            {
                //GenerateSignatureResult result = new GenerateSignatureResult();
                string plainText = "";
                if (compactJson != "")
                {
                    string encodedData = Encode.Base64Encode(compactJson);
                    plainText = String.Format("data={0}&method={1}&nonceStr={2}&requestUrl={3}&signType={4}&timestamp={5}", encodedData, method, nonceStr, requestUrl, signType, timestamp);
                }
                else
                {
                    plainText = String.Format("method={0}&nonceStr={1}&requestUrl={2}&signType={3}&timestamp={4}", method, nonceStr, requestUrl, signType, timestamp);
                }
                byte[] plainTextByte = Encoding.UTF8.GetBytes(plainText);
                RSACryptoServiceProvider provider = PemKeyUtils.GetRSAProviderFromPemFile(privateKey);
                string prikey      = provider.ToXmlString(true);
                byte[] signedBytes = provider.SignData(plainTextByte, CryptoConfig.MapNameToOID("SHA256"));
                signedData = Convert.ToBase64String(signedBytes);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(signedData);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            RSACryptoServiceProvider provider = PemKeyUtils.GetRSAProviderFromPemFile(@"C:\Users\nmose\Desktop\rsa\rsa_2048_pub.pem");
            AesCryptoServiceProvider aes      = new AesCryptoServiceProvider();


            string originFile = @"C:\Users\nmose\Desktop\rsa\info.txt";
            string encryFile  = @"C:\Users\nmose\Desktop\rsa\info-crypto.bin";
            string decrypFile = @"C:\Users\nmose\Desktop\rsa\info-decrypto.txt";
            string msg        = "";

            CryptoFile.GenerateEncryFile(provider, aes, originFile, encryFile, ref msg);

            RSACryptoServiceProvider providerPrivate = PemKeyUtils.GetRSAProviderFromPemFile(@"C:\Users\nmose\Desktop\rsa\rsa_2048_priv.pem");

            CryptoFile.DecrypFile(providerPrivate, encryFile, decrypFile, ref msg);
        }
Exemple #3
0
    public static byte[] RSAEncryptBytes(byte[] dataToEncrypt, string publicKeyPath)
    {
        RSACryptoServiceProvider provider = PemKeyUtils.GetRSAProviderFromPemFile(publicKeyPath);

        return(provider.Encrypt(dataToEncrypt, false));
    }