using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Security.Cryptography; public class Programa { public static void Main(string[] args) { var methodName = "Tools/SubscriberCampaignActivation".ToLower(); var stringToHash = "5aafc741ff855d9e" + methodName; string methodHash = ""; using (MD5 md5Hash = MD5.Create()) { byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(stringToHash)); StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) {sBuilder.Append(data[i].ToString("x2"));} methodHash = sBuilder.ToString(); Console.WriteLine("The MD5 hash of " + stringToHash + " is: " + methodHash + "."); } string publicKey = "<RSAKeyValue><Modulus>wEyodsTjUtDbb8A652Dh/ZPwLoZKAA9N20T5hiUNtGFxnSRWh9xB1WIAwtnz9FDLsT73PiiPyiBLhmI511cyAC+upKqKCtk7OR0fHzlRaH/h7H71X4PAxxes0xYLuEaPwNcanLSB1Tb5e84/JqrZhSqkIxaV5CgNVlRwiU7V5WM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"; Encryptor encryptor = new Encryptor(); string token = encryptor.EncryptRSA(methodHash, publicKey); Console.WriteLine("RSA is: " + token); } } class Encryptor { private static UnicodeEncoding _encoder = new UnicodeEncoding(); public string EncryptRSA(string data, string publicKey) { try{ var rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(publicKey); var dataToEncrypt = _encoder.GetBytes(data); byte[] encryptedByteArray = rsa.Encrypt(dataToEncrypt, false);//.ToArray(); var length = encryptedByteArray.Length;//Count var item = 0; var sb = new StringBuilder(); Console.WriteLine("RSA ECncrypt is: " + encryptedByteArray.Length); Console.WriteLine("RSA ECncrypt is: " + data); for(var i = 0; i < data.Length;++i){ Console.WriteLine(data[i]); } foreach (var x in encryptedByteArray){ item++; sb.Append(x); if (item < length) sb.Append(",");} return sb.ToString(); }catch (Exception ex) { throw new RSAException(); } } class RSAException : Exception { public RSAException() : base("RSA Encryption Error"){} } }
Standard input is empty
The MD5 hash of 5aafc741ff855d9etools/subscribercampaignactivation is: b1b33f289f2fe34e40347341311f1819. RSA ECncrypt is: 128 RSA ECncrypt is: b1b33f289f2fe34e40347341311f1819 b 1 b 3 3 f 2 8 9 f 2 f e 3 4 e 4 0 3 4 7 3 4 1 3 1 1 f 1 8 1 9 RSA is: 2,62,167,60,41,182,30,249,95,177,246,81,172,209,240,248,58,236,217,248,16,48,48,207,118,223,27,155,71,143,151,134,224,165,129,139,233,27,217,81,211,219,124,172,253,238,214,206,50,22,44,13,242,207,23,207,36,121,10,238,34,199,213,80,62,215,33,4,95,240,151,134,205,253,180,142,43,85,245,79,135,109,207,212,42,225,29,20,104,181,51,82,52,231,78,73,67,66,69,140,225,235,144,123,41,13,134,227,189,126,192,252,222,245,135,72,93,239,167,54,218,191,12,118,204,193,5,143