Crypto Utility : Encrypt Decrypt « Security « C# / C Sharp






Crypto Utility

        

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;

public static class CryptoUtility
{
    public static byte[] GetRandomBytes(int size)
    {
        byte[] randomBytes = new byte[size];
        GetRandomBytes(randomBytes);
        return randomBytes;
    }

    public static void GetRandomBytes(byte[] bytes)
    {
        RNGCryptoServiceProvider.Create().GetBytes(bytes);
    }

    public static byte[] CombineBytes(byte[] buffer1, byte[] buffer2)
    {
        byte[] combinedBytes = new byte[buffer1.Length + buffer2.Length];
        Buffer.BlockCopy(buffer1, 0, combinedBytes, 0, buffer1.Length);
        Buffer.BlockCopy(buffer2, 0, combinedBytes, buffer1.Length, buffer2.Length);

        return combinedBytes;
    }
}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Encrypt Utils
2.Decrypt Utils
3.Provides the Unix crypt() encryption algorithm.
4.Encrypts the value by password and salt.
5.Encrypt/Decrypt String To Bytes
6.Encrypt the given string using AES
7.Decrypt/Encrypt String AES
8.Encrypt String
9.Encrypt and Decrypt String
10.Encrypt a string
11.Crypto Utilities
12.Encryption Helper
13.Key Creator
14.S3 Upload Policy