public async Task <IActionResult> Auth(AuthModel model) { var username = model.userName; var password = model.password; var response = ResponseModelFactory.CreateInstance; DncUser user; //RSAHelper rSAHelper = new RSAHelper // (RSAType.RSA, Encoding.UTF8, CeyhConfiguration.TheRSASetting.Private, CeyhConfiguration.TheRSASetting.Public); await using (_dbContext) { user = await _dbContext.DncUser.FirstOrDefaultAsync(x => x.LoginName == username.Trim()); if (user == null || user.IsDeleted == IsDeleted.Yes) { response.SetFailed("用户不存在"); return(Ok(response)); } var userP = _rSaHelper.Decrypt(user.Password); var modelP = _rSaHelper.Decrypt(password.Trim()); //var s1 = rSAHelper.Decrypt(password.Trim()); if (userP != modelP) { response.SetFailed("密码不正确"); return(Ok(response)); } if (user.IsLocked == IsLocked.Locked) { response.SetFailed("账号已被锁定"); return(Ok(response)); } if (user.Status == UserStatus.Forbidden) { response.SetFailed("账号已被禁用"); return(Ok(response)); } } var claimsIdentity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, username), new Claim("guid", user.Guid.ToString()), new Claim("avatar", ""), new Claim("displayName", user.DisplayName), new Claim("loginName", user.LoginName), new Claim("emailAddress", ""), new Claim("guid", user.Guid.ToString()), new Claim("userType", ((int)user.UserType).ToString()) }); var token = JwtBearerAuthenticationExtension.GetJwtAccessToken(_appSettings, claimsIdentity); response.SetData(token); return(Ok(response)); }
public ActionResult VerifyOTP(string OTP, string HashCode, string OrderedItems, string username, string userPhone, string userEmail, string address, string restaurant) { ArrayList arrStatus = new ArrayList(); var rsa = new RSAHelper(RSAType.RSA2, Encoding.UTF8, privateKey, publicKey); Enduser VerifyOTP = new Enduser { OTP = rsa.Decrypt(HashCode) }; if (VerifyOTP.OTP == OTP) { // Insertion to tables and generation of order id code will go here.. var OrderId = CreateNewOrder(OrderedItems, username, userPhone, userEmail, address, 1, "", restaurant);// delivery mode is 1(COD) and paymentID is blank if (OrderId != Guid.Empty) { return(Json(OrderId)); } else { return(Json("00000000-0000-0000-0000-000000000000")); } } else { return(Json("Error")); } }
static public int Decrypt(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif RSAHelper self = (RSAHelper)checkSelf(l); System.String a1; checkType(l, 2, out a1); System.Boolean a2; checkType(l, 3, out a2); var ret = self.Decrypt(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
internal void Decrypt_Data <ED>(ref ED encrytedData, ref SafeData safeData) where ED : IRequest { string desDecrypted = string.Empty; using (RSAHelper rsa = new RSAHelper(RSAType.RSA2, Encoding.UTF8, Globals.key_private, Globals.key_public)) { desDecrypted = rsa.Decrypt(safeData.Des); } using (RSAHelper rsa_partner = new RSAHelper(RSAType.RSA2, Encoding.UTF8, Globals.key_private, apiUser.PublicKey)) { if (rsa_partner.Verify(desDecrypted, safeData.Signature) == false) { throw new ApiException(CodeStatus.Signature_Not_Valid); } } using (DESParameters desParameters = JsonConvert.DeserializeObject <DESParameters>(desDecrypted)) { TripleDESHelper des = new TripleDESHelper(desParameters); string message = des.Decrypt(safeData.Data); encrytedData = JsonConvert.DeserializeObject <ED>(message); request.User_ID = apiUser.User_ID; encrytedData.SetBase(request); } chainLogger.Step(Tool.GetCurrentMethod()); Access_Authorization(); Save_Request(); }
public void Decode() { var data = RSAHelper.Decrypt(output.text.Trim(), privateKey); Debug.Log(data); output.text = data; }
public AuthenticationTicket Unprotect(string protectedText) { try { if (protectedText == null) { return(default(AuthenticationTicket)); } Base64UrlTextEncoder encoder = new Base64UrlTextEncoder(); var protectedData = encoder.Decode(protectedText); if (protectedData == null) { return(default(AuthenticationTicket)); } var userData = rsa.Decrypt(protectedData); if (userData == null) { return(default(AuthenticationTicket)); } return(_serializer.Deserialize(userData)); } catch { // TODO trace exception, but do not leak other information return(default(AuthenticationTicket)); } }
public OutputModel Post([FromBody] InputModel input) { OutputModel response = new OutputModel(); string inputData = RSAHelper.Decrypt(WebConfig.PrivateKey, input.Params); PointModel userPoint = JsonConvert.DeserializeObject <PointModel>(inputData); // 参数错误 if (userPoint == null) { response.Result = "params invalid"; response.Code = 403; return(response); } // 验证码 cache丢失 object currentX = CacheHelper.GetCache(userPoint.Token); if (currentX == null) { response.Result = "Cache lost"; response.Code = 404; return(response); } if (userPoint.x <= (int)currentX + 1 && userPoint.x >= (int)currentX - 1) { response.Code = 200; response.Result = "success"; } return(response); }
public static string DecryptToBase64(string private_key_xml, string raw, bool fOAEP) { RSAHelper rsa = new RSAHelper(); rsa.SetPrivateKey(private_key_xml); return(rsa.Decrypt(raw, fOAEP)); }
public void RSAHelper_Encrypt_By_Public_Decrypt_Success() { string input = "Hello, this is Shawn, I am learning about RSA by using BigInteger class"; var bytes = Encoding.UTF8.GetBytes(input); var resultBytes = RSAHelper.Encrypt(bytes, _rsaPublic); string result = Convert.ToBase64String(resultBytes); Debug.WriteLine("Encrypt by public key: "); Debug.WriteLine(result); EncDec ed = new EncDec(); string encryptedByED = ed.RSAEncrypt(_rsaPublicXml, input); Debug.WriteLine("WARNNING: Encrypt result are {0} equal between RSAHelper and EncDec class.", encryptedByED == result ? "" : " NOT ", ""); byte[] decryptBytes = RSAHelper.Decrypt(Convert.FromBase64String(result), _rsaPrivate); string resultDecrypted = Encoding.UTF8.GetString(decryptBytes, 0, decryptBytes.Length); Debug.WriteLine("Decrypt by public key: "); Debug.WriteLine(resultDecrypted); string resultED = ed.RSADecrypt(_rsaPrivateXml, encryptedByED); Assert.AreEqual(input, resultDecrypted); Assert.AreEqual(input, resultED); }
public OutputModel Login([FromBody] InputModel input) { OutputModel response = new OutputModel(); string inputData = RSAHelper.Decrypt(WebConfig.PrivateKey, input.Params); LoginInputModel user = JsonConvert.DeserializeObject <LoginInputModel>(inputData); // 参数错误 if (user == null) { response.Result = "params invalid"; response.Code = 403; return(response); } UserDto userDto = new UserDto() { UserName = user.UserName, Password = MD5Encrypt.Getmd5(user.Password) }; var output = userService.Login(userDto); response.Code = output.Flag? 200 : 204; response.Result = output.Msg; response.Data = output.Token; return(response); }
public static void RSATest() { string data = "123456"; //2048 公钥 string publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoQh0wEqx/R2H1v00IU12Oc30fosRC/frhH89L6G+fzeaqI19MYQhEPMU13wpeqRONCUta+2iC1sgCNQ9qGGf19yGdZUfueaB1Nu9rdueQKXgVurGHJ+5N71UFm+OP1XcnFUCK4wT5d7ZIifXxuqLehP9Ts6sNjhVfa+yU+VjF5HoIe69OJEPo7OxRZcRTe17khc93Ic+PfyqswQJJlY/bgpcLJQnM+QuHmxNtF7/FpAx9YEQsShsGpVo7JaKgLo+s6AFoJ4QldQKir2vbN9vcKRbG3piElPilWDpjXQkOJZhUloh/jd7QrKFimZFldJ1r6Q59QYUyGKZARUe0KZpMQIDAQAB"; //2048 私钥 string privateKey = "MIIEpAIBAAKCAQEAoQh0wEqx/R2H1v00IU12Oc30fosRC/frhH89L6G+fzeaqI19MYQhEPMU13wpeqRONCUta+2iC1sgCNQ9qGGf19yGdZUfueaB1Nu9rdueQKXgVurGHJ+5N71UFm+OP1XcnFUCK4wT5d7ZIifXxuqLehP9Ts6sNjhVfa+yU+VjF5HoIe69OJEPo7OxRZcRTe17khc93Ic+PfyqswQJJlY/bgpcLJQnM+QuHmxNtF7/FpAx9YEQsShsGpVo7JaKgLo+s6AFoJ4QldQKir2vbN9vcKRbG3piElPilWDpjXQkOJZhUloh/jd7QrKFimZFldJ1r6Q59QYUyGKZARUe0KZpMQIDAQABAoIBAQCRZLUlOUvjIVqYvhznRK1OG6p45s8JY1r+UnPIId2Bt46oSLeUkZvZVeCnfq9k0Bzb8AVGwVPhtPEDh73z3dEYcT/lwjLXAkyPB6gG5ZfI/vvC/k7JYV01+neFmktw2/FIJWj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HnTWgxwNpTsBCgXu8Q=="; string encryptStr = RSAHelper.Encrypt(data, publicKey); Console.WriteLine($"encryptStr={encryptStr}"); Console.WriteLine(); string data2 = RSAHelper.Decrypt(encryptStr, privateKey); Console.WriteLine($"data2={data2}"); Console.WriteLine(); string signStr = RSAHelper.SignWithSHA256(data, privateKey); Console.WriteLine($"sign={signStr}"); Console.WriteLine(); bool verify = RSAHelper.VerifyWithSHA256(data, signStr, publicKey); Console.WriteLine($"verify={verify}"); Console.WriteLine(); }
public void DecryptTest() { string data = "F6X2AYVBfiQvWe9XG7HpGU6nNAdDNCW86PPRJ1hVCDYsHPKZMdyLmmod7x1uyL7Utz2MVPQUkC0VURE8pqnVNaeWd8MGqo1FnMx30ENUdHWep4H/J2ZEX+4Uitiy51yqCc9UW02APoTP7iPWNmkJf8InPB70DlZCeMA4dS2v2NB2HDEgUwgVVr50LB6Idp8yk42gpmGh7C/hGRO/6xEOfBpQ/krmsD9jZ2IErdpK7YGfXJ6xyy0Qa5q3WccLO4SCyOI0NlF4gMSCOO1UOFhcqozgenOnsdKhhL8D99/FGxG0LhPaPSRMLrViBd6CzDExYS4YErGAu9ONMIMvosCH4w=="; RSAHelper rsa = new RSAHelper(PrivateKey, PublicKey); var value = rsa.Decrypt(data); }
private void button4_Click(object sender, EventArgs e) { var rSAHelper = new RSAHelper(rsaKey2.Text); var btArray = Convert.FromBase64String(richTextBox2.Text); var result = rSAHelper.Decrypt(btArray); richTextBox2.Text = Encoding.Default.GetString(result); }
private void btnRSA2_Click(Object sender, EventArgs e) { var buf = GetBytes(); var pass = rtPass.Text; buf = RSAHelper.Decrypt(buf, pass); rtResult.Text = buf.ToStr() + Environment.NewLine + Environment.NewLine + buf.ToHex() + Environment.NewLine + Environment.NewLine + buf.ToBase64(); }
private void btnRSA2_Click(Object sender, EventArgs e) { var buf = GetBytes(); var pass = rtPass.Text; buf = RSAHelper.Decrypt(buf, pass); SetResult2(buf); }
public void EncryptTest() { var publicKey = @"<RSAKeyValue><Modulus>4cedf65bJcLZen/qnNUn1WXwzCJGp8x1nnKaBiBmYmNxCB6aIDwToqWLFonL/4FHMDItItw3PVkMWK3hMJ+5TZpB36H56iW06EYRtba4rviKb5KF/i+fbREqE4rADxBZIb/d1hP29ciA7D/JP6Cd6FreHWa42HaHXfeqsEHsjAE=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"; var privateKey = @"<RSAKeyValue><Modulus>4cedf65bJcLZen/qnNUn1WXwzCJGp8x1nnKaBiBmYmNxCB6aIDwToqWLFonL/4FHMDItItw3PVkMWK3hMJ+5TZpB36H56iW06EYRtba4rviKb5KF/i+fbREqE4rADxBZIb/d1hP29ciA7D/JP6Cd6FreHWa42HaHXfeqsEHsjAE=</Modulus><Exponent>AQAB</Exponent><P>6aG9bMiBbgflnj9Rleng7vBQQPuWuuR7ETMw9XQnL1WLxEeZs8zn36Ph+ziSg6TDvOhBHlLC49lmHdvha0vJpw==</P><Q>92VsZInwwVfUVL/oyS87Ya4PR0FBRI9pZJyR6C4TTf7vTMCBC2XDV6uRC+m9RU/JypEuOsp8+WLgBVHlrCjiFw==</Q><DP>HvjCE9nAzsVdO01Jk4Ydu49AFF1F7iC779vJccCkMTI2BR840Q0o8AzZuGQXiDwfdruTZmGyVGJNl0e+6mpxoQ==</DP><DQ>R5wqBegPskdUBLwQC7wKOjoB3iQ7WjcQ0LipW0WK/PagGd1W/Q+VvZjBwWsFCD0SMfpYIVhfWGiQY7nS+0RSPQ==</DQ><InverseQ>MC5PTTSaiCRRGerW9CpWq6k+b1pBT5q3QO0TonmqPVoJ5dyprVgeHmLUPkmefKcqLQh8+5Bdw15fjJfI9g8iBg==</InverseQ><D>MOcemxA119j7aAga1ftpVFRvMpfd++xSMY6bA+aypm7phZuzQHYivqDinnAcSmxC8hJ8KkfOgzAtd2u6EeEWrmshZ04ZZ+doDc+aejLBcm+CtvqzW10loMIdbsoAYxGw+TV3P8sddRU7xQjbR6nLmcudzAFQiV3yoOe6Ynp7Wo0=</D></RSAKeyValue>"; var cipher = RSAHelper.Encrypt("cszfp.com", publicKey); var clear = RSAHelper.Decrypt(cipher, privateKey); Assert.AreEqual("cszfp.com", clear); }
public void RSAHelperSelfEncryptAndDecrypt() { RSAHelper helper1 = new RSAHelper(); string original = "This is test message"; byte[] encrypted = helper1.Encrypt(original); string decrypted = helper1.Decrypt(encrypted); Assert.Equal(original, decrypted); }
public void EncryptDecrypt() { string data = "123456"; string encryptStr = RSAHelper.Encrypt(data, PUBLICKEY); string data2 = RSAHelper.Decrypt(encryptStr, PRIVATEKEY); Assert.Equal(data, data2); }
public static string DecriptRespose(ApiResponse response) { string des = RSAHelper.Decrypt(response.Des, Env.PartnerPrivateKey); if (!RSAHelper.Verify(des, response.Signature, Env.RfiPublicKey)) { throw new Exception("Signature not valid"); } return(TripleDESHelper.Decrypt(response.Data, des)); }
public void Decrypt() { (var cipherBytes, var key, var clear) = Encrypt(); //公钥解密 var clearBytes = RSAHelper.Decrypt(cipherBytes, key.PublicKey); var deClear = Encoding.Default.GetString(clearBytes.ToArray()); //原文与解密后的原文必须一致 Assert.True(clear == deClear); }
public static string Rsas(RsaDto dto) { //2048 公钥 string publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoKefXtIqc293nDjFpCkjUuyEL3bc15lVlocJJVdQovRLyTKXpzcD029U0MeVAd8Hq9huQtxWspV+/KSoXjN5BGc7XS/QZItG1irxtivIHlFmzra7Fk94r10F4/hR/mdq+H/WAIJJjGpw1Garncvh8AEJXJ2JBbiAyM0zNSqDNidTFFPuLoGQQ+EGsbCESMFy0mGeSBd8/b6ADwLiRXuAiNo3ArFRui2fwuljXyFP2EC1aRNIF8qc5GkikBkqUPKQrQ29H2cfQEpbxj2LP4hOLmuO+U2snMN3DRyTMnONJWN10x08VlCsZUS9fHJnR6kkU5PYodpJQ8hI1Uloy7TH5wIDAQAB"; //2048 私钥 string privateKey = "MIIEogIBAAKCAQEAzDueGtt83DiINqNbH9/i0gWES7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j1E9awrfKTUxefT2y4YpSk7j9J+Ltl0di7nvT7U8LESJ4SqbDMS/wqJTs13KZb+EMDPFSnp/1P9LqPyN0s6sKHWEH4dZqNSIKSjHFsQKBgGdWQe7wdtNAuUIMhJsmiRBQMK4BxfhIUFTIzbS0TEQtUk/dRqflavOoMsO6AONeXJSmQjDNPJ0ODpTUdFkQuELkioZ7Up1XrWeV0OVta9Rai5qg/85NcE9P7yqurSCazdzICva5sphIJR1szRGxVf9Uwa8G8gNiiMTFN5LWz+/5AoGAeBflK25j80/kFK3+ZKe+33B+atN/OLV4qEh5G1m888oj8rWa+iWfQFCZZkRL7S+nMXnx9hzNRRjJoKPlT7qlePHEhVCr4ruQ8mzN8VPRSyaRBIV7lg5M9li43SWjsCD4yT390MmgJYrLpT/9txblUqhQUXn/tZ0kM3uEKHieOsc="; var rsa = new RSAHelper(RSAType.RSA2, Encoding.UTF8, privateKey, publicKey, ""); return(rsa.Decrypt(dto.rsaName)); }
public override void OnActionExecuting(HttpActionContext actionContext) { try { Stream stream = actionContext.Request.Content.ReadAsStreamAsync().Result; Encoding encoding = Encoding.UTF8; stream.Position = 0; string responseData = ""; using (StreamReader reader = new StreamReader(stream, encoding)) { responseData = reader.ReadToEnd().ToString(); } var realData = string.Empty; try { realData = RSAHelper.Decrypt(responseData); } catch { actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "请求数据异常。"); return; } foreach (var argument in actionContext.ActionArguments) { Type type = argument.Value.GetType(); PropertyInfo[] ps = type.GetProperties(); foreach (PropertyInfo i in ps) { string name = i.Name; if (name == "data") { i.SetValue(argument.Value, realData); break; } } } } catch { actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "服务授权信息校验异常。"); } }
public void EncryptAndDecrypt() { var prvKey = @"-----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEAnzyis1ZjfNB0bBgKFMSvvkTtwlvBsaJq7S5wA+kzeVOVpVWw kWdVha4s38XM/pa/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6w1vzz1zwKz 5pTpPI0OjgWN13Tq8+PKvm/4Ga2MjgOgPWQkslulO/oMcXbPwWC3hcRdr9tcQtn9 Imf9n2spL/6EDFId+Hp/7QKBgAqlWdiXsWckdE1Fn91/NGHsc8syKvjjk1onDcw0 NvVi5vcba9oGdElJX3e9mxqUKMrw7msJJv1MX8LWyMQC5L6YNYHDfbPF1q5L4i8j 8mRex97UVokJQRRA452V2vCO6S5ETgpnad36de3MUxHgCOX3qL382Qx9/THVmbma 3YfRAoGAUxL/Eu5yvMK8SAt/dJK6FedngcM3JEFNplmtLYVLWhkIlNRGDwkg3I5K y18Ae9n7dHVueyslrb6weq7dTkYDi3iOYRW8HRkIQh06wEdbxt0shTzAJvvCQfrB jg/3747WSsf/zBTcHihTRBdAv6OmdhV4/dD5YBfLAkLrd+mX7iE= -----END RSA PRIVATE KEY-----"; var pubKey = @"-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnzyis1ZjfNB0bBgKFMSv vkTtwlvBsaJq7S5wA+kzeVOVpVWwkWdVha4s38XM/pa/yr47av7+z3VTmvDRyAHc aT92whREFpLv9cj5lTeJSibyr/Mrm/YtjCZVWgaOYIhwrXwKLqPr/11inWsAkfIy tvHWTxZYEcXLgAXFuUuaS3uF9gEiNQwzGTU1v0FqkqTBr4B8nW3HCN47XUu0t8Y0 e+lf4s4OxQawWD79J9/5d3Ry0vbV3Am1FtGJiJvOwRsIfVChDpYStTcHTCMqtvWb V6L11BWkpzGXSW4Hv43qa+GSYOD2QU68Mb59oSk2OB+BtOLpJofmbGEGgvmwyCI9 MwIDAQAB -----END PUBLIC KEY-----"; // 最大只能214 var data = Rand.NextBytes(214); var buf = RSAHelper.Encrypt(data, pubKey); Assert.NotNull(buf); var rs = RSAHelper.Decrypt(buf, prvKey); Assert.Equal(data.ToBase64(), rs.ToBase64()); }
private bool checkTokenValid(string cyphertext, string useraddress) { var plaintext = RSAHelper.Decrypt(cyphertext); var tokearr = plaintext.Split(','); if (tokearr.Length == 2) { if (useraddress == tokearr[1].ToString()) { return(true); } } return(false); }
public async Task <ActionResult <ResponseModel <UserEditViewModel> > > Edit(Guid guid) { await using (_dbContext) { var entity = await _dbContext.DncUser.FirstOrDefaultAsync(x => x.Guid == guid); var response = ResponseModelFactory.CreateInstance; var resEntity = _mapper.Map <DncUser, UserEditViewModel>(entity); if (entity != null) { resEntity.Password = _rSaHelper.Decrypt(entity.Password); } response.SetData(resEntity); return(Ok(response)); } }
public void RSAHelperCrossEncryptAndDecrypt() { RSAHelper receiver = new RSAHelper(); RSAHelper sender = new RSAHelper(); sender.SetPeerPublicKey(receiver.MyPublicKey); receiver.SetPeerPublicKey(sender.MyPublicKey); string original = "This is test message"; byte[] encrypted = sender.Encrypt(original); string decrypted = receiver.Decrypt(encrypted); Assert.Equal(original, decrypted); }
private void btnRSA2_Click(Object sender, EventArgs e) { var buf = GetBytes(); var pass = rtPass.Text; try { buf = RSAHelper.Decrypt(buf, pass, true); } catch (CryptographicException) { // 换一种填充方式 buf = RSAHelper.Decrypt(buf, pass, false); } SetResult2(buf); }
private bool CheckUser(string email, string password) { var user = _userService.GetUserByEmail(email); if (user == null) { return(false); } var passwordDecrypt = RSAHelper.Decrypt(password, TempData["RSAKey"].ToString()); if (HashHelper.HashMd5(passwordDecrypt, user.Salt) != user.Password) { return(false); } return(true); }
private void GenerateAndSendAESKey(byte[] inputData, TcpClient tcpClient) { string guid = System.Guid.NewGuid().ToString(); byte[] clientPublicKey = RSAHelper.Decrypt(inputData, this.RSAKey); AESKey key = AESKey.Generate(); this.AESKeyList.Add(guid, key); MessageBody message = new MessageBody() { Guid = guid, Content = RSAHelper.Encrypt(this.JsonSerialzation.Serialize(key), clientPublicKey), Flag = MessageFlag.SendAESKey }; this.SendMessage(message, tcpClient); }
public void RSAHelper_Encrypt_By_Private_Decrypt_Success() { string input = "Hello, this is Shawn, I am learning about RSA by using BigInteger class"; var bytes = Encoding.UTF8.GetBytes(input); var resultBytes = RSAHelper.Encrypt(bytes, _rsaPrivate); string result = Convert.ToBase64String(resultBytes); Debug.WriteLine("Encrypt by private key: "); Debug.WriteLine(result); byte[] decryptBytes = RSAHelper.Decrypt(Convert.FromBase64String(result), _rsaPublic); string resultDecrypted = Encoding.UTF8.GetString(decryptBytes, 0, decryptBytes.Length); Debug.WriteLine("Decrypt by public key: "); Debug.WriteLine(resultDecrypted); Assert.AreEqual(input, resultDecrypted); }