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

26 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. Buy online wholesale printed custom cbd boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!

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

    ReplyDelete
  9. Blackbird packaging provide you with any size, shape design, custom bath bomb display boxes sooner than any other packaging competitor in the market

    ReplyDelete
  10. Great Article
    Cloud Computing Projects




    Networking Projects



    Final Year

    Projects for CSE





    JavaScript Training in Chennai



    JavaScript

    Training in Chennai




    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals,

    Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer.

    Angular Training

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

    ReplyDelete
  12. 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
  13. 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
  14. Blackbird packaging provide you with any size, shape design, custom bottle neckers wholesale sooner than any other packaging competitor in the market

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

    ReplyDelete
  16. Blackbird packaging provide you with any size, shape design, essential oil packaging sooner than any other packaging competitor in the market

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

    ReplyDelete
  18. Buy best quality blood pressure device price in Pakistan online at affordable prices from medisense. Delivered at your doorstep. Get fast shipping.

    ReplyDelete
  19. Now You can get best quality multivitamins in Pakistan online from medisense where all kind of supplements and vitamins are available. Quick delivery.

    ReplyDelete
  20. Now You can buy lactogen price in Pakistan from medisense where all kind of medicine and baby foods are available. Quick delivery.

    ReplyDelete
  21. Buy best quality blood pressure machine in Pakistan online at affordable prices from medisense. Fast delivery.

    ReplyDelete
  22. Now You can buy Online certeza nebulizer price in Pakistan from medisense where all kind of nebulizer and steamers are available. Quick delivery.

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

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

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

    ReplyDelete
  26. 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