Showing posts with label Manually Encryption-Decryption customization in MVC || RAJESH GAMI. Show all posts
Showing posts with label Manually Encryption-Decryption customization in MVC || RAJESH GAMI. Show all posts

Manually Encryption-Decryption customization in MVC || RAJESH GAMI


ENC – Encryption ID

using System;
using System.Data.Entity;

namespace MyProject.Models
{
    public class enc
    {
        public static string Encrypt(int value)
        {
            string str = Convert.ToBase64String(BitConverter.GetBytes(value));
            str = str.Replace("==", "");
            str = str.Replace("+", "#");
            str = str.Replace("/", "@");
            return GetLetter() + str + GetLetter();
            //return Convert.ToBase64String(BitConverter.GetBytes(value)).Replace("==", "");
        }

        public static int Decrypt(string value)
        {
            value = value.Replace("@", "/");
            value = value.Replace("#", "+");

            if (value.Length != 6)
                throw new ArgumentException("Invalid length.");

            return BitConverter.ToInt32(Convert.FromBase64String(value + "=="), 0);
        }
        static Random _random = new Random();
        public static char GetLetter()
        {
            // This method returns a random lowercase letter.
            // ... Between 'a' and 'z' inclusize.
            int num = _random.Next(0, 26); // Zero to 25
            char let = (char)('A' + num);
            return let;
        }
        public class encContext : DbContext
        {
            public encContext()
                : base("ConString_name")
            {
            }
            public DbSet<enc> enc { get; set; }

        }
    }
}

RAJESH GAMI - Blog

Digital Signature Pad in Angular | RAJESH GAMI

  What is Signature Pad? Signature Pad could be a JavaScript library for drawing fancy signatures. It supports HTML5 canvas and uses variabl...