find a location for property in a new city

Thursday 8 September 2011

Triple DES encryption and decryption with .NET

TripleDes essentials

Start your class like this:
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace Utils
{
 public static class EncryptionHelper
 {
    static private byte[] key = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                                            15, 16, 17, 18, 19, 20, 21, 22, 23, 24};
    static private byte[] iv8Bit = { 1,2,3,4,5,6,7,8 };

TripleDes Encryption

Add the following method for encrypting with Triple DES:
public static string TripleDesEncryption(string dataToEncrypt)
{
   var bytes = Encoding.Default.GetBytes(dataToEncrypt);
   using (var tripleDes= new TripleDESCryptoServiceProvider())
   {
    using (var ms = new MemoryStream())
    using (var encryptor = tripleDes.CreateEncryptor(key, iv8Bit))
    using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
    {
     cs.Write(bytes, 0, bytes.Length);
     cs.FlushFinalBlock();
     var cipher = ms.ToArray();
     return Convert.ToBase64String(cipher);
    }
   }
}

Triple DES Decryption

The next method will allow decryption of your data
public static string TripleDesDecryption(string dataToDecrypt)
{
   var bytes = Convert.FromBase64String(dataToDecrypt);
   using (var tripleDes= new TripleDESCryptoServiceProvider())
   {
    using (var ms = new MemoryStream())
    using (var decryptor = tripleDes.CreateDecryptor(key, iv8Bit))
    using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Write))
    {
     cs.Write(bytes, 0, bytes.Length);
     cs.FlushFinalBlock();
     var cipher = ms.ToArray();
     return Encoding.UTF8.GetString(cipher);
    }
   }
}

Follow britishdev on Twitter

19 comments:

  1. Motifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium embroidered Lawn, Premium lawn, Premium lawn 2019, Motifz, Premium lawn in Pakistan. Shipping worldwide. Stitching option available.

    ReplyDelete
  2. I surely getting a charge out of every single bit of it. It is an uncommon site and lovely offer.It is in motivation behind reality a mind blowing and pleasing piece of data. I'm satisfied that you basically granted this significant information to us. If its all the same to you keep awake with the most recent like this. An obligation of appreciation is all together for sharing. Visit site Cheap essay writing service

    ReplyDelete
  3. The .NET framework is backward compatible, i.e. you can use a function used in .NET 1 in 2 or you can compile and run a Master Thesis Writing Service program developed in .NET 1 in system with .NET 2 and .NET 3. Like wise you can also run programs developed in .NET 2 in system with .NET 3. This is called as Backward compatibility, i.e. support for previous versions how to write dissertation online UK.

    ReplyDelete
  4. Hi, i am Angylinca Wilson. Encryption and description is very interesting topic for Networking. Its very secure and valuable. Now, I am working coursework help at very affordable price for other company. so students orders now.

    ReplyDelete
  5. I think Encryption is a scheme where an intelligible text plaintext in crypto terms is made unintelligible ciphertext in crypto terms using a secure key. Block and stream ciphers and public key systems do this work. The security of the ciphers reside in the key length and decryption processbest cheap essay writing services in UK is a difficult without proper knowledge of the key.

    ReplyDelete
  6. Very well Excellent information If could you need some logistics services Best air freight companies is offering all logistics services the workforce is well trained and they are profession and deliver your godds one place to another timely.

    ReplyDelete
  7. Blackbird packaging provide you with any size, shape design, makeup boxes sooner than any other packaging competitor in the market

    ReplyDelete
  8. buy custom cookie boxes online from blackbird packaging at best prices. get free shiping

    ReplyDelete
  9. Shop electronics online in lahore Goods at Al-Fatah, Pakistan’s leading chain of departmental stores. Shop from a huge range of top brands Home Appliances, Smart-tech and Phones and Sound bars from Al-Fatah. Shop from huge range of electronics available at Al-Fatah. Avail Free Delivery on orders above 1000 PKR in selected cities.

    ReplyDelete
  10. The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals full size cotton sheets on sale , cheap comforter sets under 30

    ReplyDelete
  11. Buy best quality sexual products online shopping in Pakistan from medisense at your door step. Quick delivery. Order Now!

    ReplyDelete
  12. Buy leggings for women online from Dshred at easy prices delivered at your doorstep. Get free shipping

    ReplyDelete
  13. Buy gym trousers for men online dshred at best prices delivered at your doorstep. Get free shipping

    ReplyDelete
  14. Buy t shirt for men online from dshred at best prices delivered at your doorstep. Get free shipping

    ReplyDelete
  15. Security is the main feature of every system. You deliver the informative information about triple des encryption and decryption. Thank you for sharing information. Moreover, If you want to get mover's services, then you should hire best local movers in Springfield for best services.

    ReplyDelete
  16. Borjan offers its customers the best training shoes for men online in Pakistan. We have the highest quality training shoes in Pakistan for the most affordable prices. Get Borjan's amazing collection of men's training shoes online. Get your favorite shoes for men from Borjan to enjoy style and comfort at the same time.

    ReplyDelete
  17. From Ndure buy online the latest fashion women track suits online at affordable price. Fast Shipping.

    ReplyDelete
  18. Your blogs are great.Are you also searching for Cheap Nursing Writing company? we are the best solution for you. We are best known for delivering cheap nursing writing services to students without having to break the bank.whatsapp us:+1-(951)-468-9855

    ReplyDelete
  19. Great Platform. Are you also searching for nursing essay writing help? we are the best solution for you. We are best known for offering the best nursing essay writing services

    ReplyDelete