Saturday, October 30, 2021

Public Key Encryption (RSA Method) for Encryption and Decryption in ASP.Net

 We already know about DES algorithm  method

The RSA Public Key Encryption is useful method for Encryption and Decryption .The Code behind the Method is mention below.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.IO; 

public
 class Tester

    public static void Main()
    {
        RSACryptoServiceProvider myRSAProvide = new RSACryptoServiceProvider();
        string strCrypt = null;
        byte[] bteCrypt = null;
        byte[] bteResult = null;
        try
        {
            strCrypt = "12345678";
            bteCrypt = Encoding.ASCII.GetBytes(strCrypt);
            bteResult = myRSAProvide.Encrypt(bteCrypt, false);
            Console.WriteLine(Encoding.ASCII.GetString(bteResult));
         }
        catch (CryptographicException ex)
        {
            Console.WriteLine(ex.Message);
        }
         string strResault = null;
        byte[] bteDecrypt = null;
        try
        {
            bteDecrypt = myRSAProvide.Decrypt(bteResult, false);
            strResault = Encoding.ASCII.GetString(bteDecrypt);
            Console.WriteLine(strResault);
        }
        catch (CryptographicException ex)
        {
            Console.WriteLine(ex.Message);
        }
         Console.ReadLine();
    }
}

It is very simple pubic key encryption and decryption method.

    No comments:

    Post a Comment

    No String Argument Constructor/Factory Method to Deserialize From String Value

      In this short article, we will cover in-depth the   JsonMappingException: no String-argument constructor/factory method to deserialize fro...