Test .Net Framework is correctly installed and working fine

Task: Test .Net Framework is correctly installed and working fine.

Description: We can test by creating a aspx file using below code for checking .Net Framework is correctly installed and working fine.

<%@ Page Language="C#"%>
<%@ Import Namespace=Microsoft.Win32 %>
<script runat="server">
void Page_Load(Object s, EventArgs e)
{
    Label1.Text = "The "+Environment.Version+" .NET Framework <b>is</b> correctly installed and working";
    Label2.Text = "Running on machine " + Environment.MachineName + " at " + System.DateTime.Now.ToString();
 }   
</script>
<!DOCTYPE html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>ASP.NET Test</TITLE>
</HEAD>
<BODY>
<DIV align="center" style="margin-top:60px">
<table style="background-color:#ffffff; width:500px; border width:1px solid #666666;" cellpadding="8">
<tr>
<td style="font-family: arial; font-size: 17px; font-weight: bold; color: #000000;">
      ASP.NET Test
</td>
</tr>
</table>
<br><br>
<table style="background-color: #ffffff; width: 500px; border width: 1px solid #666666;" cellpadding="8">
      <tr>
      <td style="line-height:18px">
      This form will determine if .NET is working correctly
<hr noshade width='90%' size='1px'>
<asp:Label ID="Label1" Runat="server">If you can read this then .NET is <b>not</b> working correctly!</asp:Label>
<br><br>
      <asp:Label ID="Label2" Runat="server"></asp:Label>
      </td>
      </tr>
</table>
<p>&nbsp</p>
</div>
</BODY>
</HTML>

Encryption Using RSA in asp.net

Task: Encryption using RSA algorithm in asp.net.

Description: There are various Encryption-Decryption techniques. RSA is one of them. Encryption using RSA algorithm in asp.net. Here first we generate the key pair public-private key. Then we encrypt an de-crypt the data using keys.


using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;

public partial class rsaencryption : System.Web.UI.Page
{
  public void rsaencryption()
  {
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
    string publicPrivateKeyXML = rsa.ToXmlString(true); // private key - Save it
    string publicOnlyKeyXML = rsa.ToXmlString(false);  // public key

    lbl_key.Text = publicPrivateKeyXML;

    string text = TextBox1.Text; // Plain Text
    rsa.FromXmlString(publicOnlyKeyXML);
    byte[] data = Encoding.UTF8.GetBytes(text);
    byte[] cipherText = rsa.Encrypt(data, false);

    Label2.Text = Convert.ToBase64String(cipherText); // Encrypted Data
  }
 
  public void rsadecryption()
  {
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
    rsa.FromXmlString(lbl_key.Text); // Private Key as we generated at encryption

    byte[] ciphterText = Convert.FromBase64String(Label2.Text); // Encrypted Data
    byte[] plainText = rsa.Decrypt(ciphterText, false);
    Label3.Text = Encoding.UTF8.GetString(plainText); // Plain Text (Decrypted)
  }
}
 

Encryption using sha without key in asp.net

Task: Encryption using SHA without key in asp.net.

Description: Encryption using SHA in asp.net and c#. Using below code we can generate message digest. In Web technology we need to save password of user, for this we can use this one. It is one way encryption, we can't decrypt it back. Here we Encrypt data without key, for encrypt using key see here.



using System;
using System.Security.Cryptography;

using System.Text;

    private void shaEncryption(string plaintext)
    {
        byte[] data = ASCIIEncoding.ASCII.GetBytes(plaintext);
        byte[] result;
        SHA1 sha = new SHA1CryptoServiceProvider();
       
        result = sha.ComputeHash(data);
        lblencrypt.Text = "<br/>SHA Output : <br/>" + Convert.ToBase64String(result);

    }