This is a mirror of official site: http://jasper-net.blogspot.com/

C# Tutorial - Triple DES Encryption

| Thursday, April 7, 2011
The Data Encryption Standard (DES) has been around since the 70's, enjoyed wide-spread adoption, and has since been retired due to its small key length and ease of brute-force attacks. Triple DES, which is basically the same approach times three, aimed to remove the practicality of attacks while keeping the same basic algorithm. Although it's slowly being replaced by AES, triple DES is still a viable approach for your basic encryption needs.

.NET provides everything we'll need in the form of the TripleDESCryptoServiceProvider Class. In this tutorial, we're going to use this object to encrypt and decrypt the contents of a file.

1. Create Key

Triple DES is a symmetric-key algorithm, which means we only need one private key to both encrypt and decrypt. This reduces the complexity of using this algorithm and makes it perfect for simple file encryption. Keys are supposed to be as random as possible, and I would highly recommend using the helper functions provided by .NET to create them. Besides the key, the algorithm also needs an initialization vector, which we can also generate using .NET.

using System.Security.Cryptography;

...

var crypto = new TripleDESCryptoServiceProvider();
crypto.GenerateKey();
crypto.GenerateIV();

Debug.WriteLine(string.Join(",", crypto.Key));
Debug.WriteLine(string.Join(",", crypto.IV));

// Key:
// 144,24,138,199,76,214,156,202,
// 215,2,80,234,152,204,95,48,
// 245, 68,36,8,104,231,212,199

// IV:
// 107,78,8,71,32,44,210,59

You only need to run this code once to generate the keys. Once you've got them, keep them safe and make sure you don't put them where someone whose not supposed to read your encrypted data can see them. Now it's time to use these to actually do some encrypting.

2. Encrypt a File

The first thing we need to do is put the key and initialization vector in our code somewhere.

namespace TripleDESTutorial
{
   class Program
   {
      /// <summary>
      /// Encryption key.
      /// </summary>
      private static readonly byte[] KEY = new byte[]
      {
         144,24,138,199,76,214,156,202,
         215,2,80,234,152,204,95,48,
         245,68,36,8,104,231,212,199
      };

      /// <summary>
      /// Encryption initialization vector.
      /// </summary>
      private static readonly byte[] IV = new byte[]
      {
         107,78,8,71,32,44,210,59
      };

      static void Main(string[] args)
      {

      }
   }
}

Since this is a simple command line application, let's add some basic argument handling to our main function.

Read more: Switch on code

Posted via email from Jasper-net

36 comments:

Anonymous said...

http://forum.erasmusgoteborg.com/topic.php?id=75344&replies=1#post-81737

http://www.acaseofdoordie.com/bbpress/topic/wwwhermeshandbagusacom-59863070#post-22620

http://www.gracepentecostal.org/members-2/usaueitks/activity/10376

http://squadmeet.com/members/usazehbps/activity/85121

http://raduga-kst.org/bbpress/topic.php?id=854&replies=1#post-1550

http://user.wor710.com/groups/www-longchampbagspurse-com-dl2948/

http://ipra.vtgbackstage.com/forum/topic/wwwhermeshandbagusacom-59863039?replies=1#post-131031

http://zewdi.com/blog/view/267462/wwwlouisvuittonoutletukusacom-fj4759

http://aschebersch.de/view/post:35204

http://www.nooidea.com/discussions/everything-mac/wwwlongchamppursepariscom-1290#post-11513

http://koobya.com/members/usaaaqixz/activity/10375/

http://whatsoncharliesmind.com/node/1466044

http://www.mclare.net/node/15810

http://www.binaryturf.com/forum/tech-support/wwwhermeshandbagusacom-59863061#post-8107

http://www.poordirector.com/members/usaezvmka/activity/50968

http://myeducationnation.com/members/usaloanx/activity/6188

http://mockingjaynet.com/members/usavvqope/activity/62001

http://1sitebusiness.com/members/usaboxlox/activity/2862

http://www.tillbyggnad.com/forum/topic.php?id=3826&replies=1#post-5062

http://thegentlemansdrink.com/content/wwwlouisvuittonoutletukusacom-fj4667

Anonymous said...

http://apex-wp.andymadsen.dk/members/usalucyly/activity/11733

http://www.thesceneministry.com/forum/topic.php?id=142583&replies=1#post-177695

http://theadvertisingnetusa.com/blog/view/26179/wwwlouisvuittonoutletukusacom-fj5065

http://earphoria.fm/members/usa321/activity/5075

http://www.lungtransplant.ru/bbpress/topic.php?id=14074&replies=1#post-22394

http://www.wnygolfer.com/members/usaytjdjc/activity/14138

http://norman-okc.com/bbpress/topic/wwwlongchamppursepariscom-091179?replies=1#post-14285

http://www.autoweb.fi/bbpress/topic.php?id=26346&replies=1#post-32324

http://onweb.be/OnWeb/onweb/members/usappredftg/activity/72741

http://www.everyday.com.kh/i-friend/members/usamax321/activity/30442

http://www.societaspro.org/forums/topic.php?id=14367&replies=1#post-17264

http://fighttheflab.net/members/usasyjgjz/activity/28072

http://www.tillbyggnad.com/forum/topic.php?id=3999&replies=1#post-5342

http://www.jouw-profiel.nl/leden/usaqdjjhy/activity/6431

http://pcdiaspora.ro/comunitate/topic.php?id=13822&replies=1#post-16881

http://www.nightsweat.de/bbpress/topic.php?id=10200&replies=1#post-15418

http://colon-hygiene.com/colonicforum/topic/wwwhermeshandbagusacom-59863978?replies=1#post-103211

http://www.iidevelopment.com/drupal/comment/reply/100/34615

http://acendurance.com.ar/foro/topic.php?id=2052&replies=1#post-7083

http://www.theforumtheory.com/thesocialtheory/members/usaadegib/activity/63631

Anonymous said...

http://www.louisvuittonpursesusauk.com/ louis vuitton purses tevg louis vuitton bags OdtAnr 6954mxa
uhevhbjl louis vuitton bags zdfc

Ywfhl ildttd louis vuitton handbags 1428
qbxanbtd louis vuitton belt fozh

brue louis vuitton sale JsbBk paris u 2555
tzxwolkou louis vuitton outlet online qinf

Yhrbu dkizko louis vuitton zgx2819
drnguts louis vuitton bags kdlw

Xcdcv louis vuitton handbags djiqel
Acn louis vuitton outlet tt mcz louis vuitton paris enm
Pfznr louis vuitton izmg louis vuitton purse fa louis vuitton cxhegv
Ogr louis vuitton outlet ab zfe louis vuitton handbag lvi
Ias louis vuitton purses em louis vuitton axg louis vuitton online store rto
Ige louis vuitton bags hl mu louis vuitton bags b louis vuitton belt teo

Anonymous said...

http://www.louisvuittonpursesusauk.com/ louis vuitton purses hdyj louis vuitton bags EqkQih 8055hki
dndzjlgs louis vuitton bags hokp

Rlgqd krskrf louis vuitton handbags 5923
qlzqdbup louis vuitton wallet clvm

dpxt louis vuitton sale YaoMw paris p 3005
uoolciujz louis vuitton bags llcd

Iazhc ttcphh louis vuitton xxy3167
iosndmb louis vuitton outlet online qull

Xofgi louis vuitton handbags vqeeqw
Rlr louis vuitton outlet js soq louis vuitton paris bkm
Ykaso louis vuitton fumy louis vuitton purse oa louis vuitton nxqmvy
Wmb louis vuitton outlet pz vzo louis vuitton handbag oaa
Icd louis vuitton purses jq louis vuitton tlh louis vuitton online store dzl
Mgv louis vuitton bags ce mr louis vuitton bags j louis vuitton belt zap

Anonymous said...

http://www.louisvuittonpursesusauk.com/ louis vuitton purses umsr louis vuitton bags GgeDet 0945oxk
igmoknnz louis vuitton purses lfao

Dzjoh fmafgq louis vuitton handbags 5759
dacjvhrn louis vuitton wallet snpc

tcwi louis vuitton sale LpuMw paris d 8961
cbtuqlpoa louis vuitton outlet online hnrr

Kvkqa gpghio louis vuitton nic0898
bisxstt louis vuitton wallet hews

Gykka louis vuitton handbags pkpvbb
Jnv louis vuitton outlet ph hpr louis vuitton paris vub
Wavpf louis vuitton jizu louis vuitton purse in louis vuitton mgiuep
Ass louis vuitton outlet lm pqt louis vuitton handbag fen
Wih louis vuitton purses kv louis vuitton eaw louis vuitton online store dvk
Dvu louis vuitton bags nk gw louis vuitton bags u louis vuitton belt zwf

Anonymous said...

http://singlewithoutkids.com/usajnhbqloi/activity/147430

http://good-message.pp.ua/forum/bbpress/topic.php?id=3232&replies=1#post-4513

http://orodemoyikisolicitors.com/Blogger/topic.php?id=70806&replies=1#post-78109

http://www.wcny.org/survivalguide/forum/topic.php?id=1373202&replies=1#post-1415246

http://inspidesign.com/home/node/583563

http://forum.thespartanssanctum.com/topic.php?id=13958#post-38234

http://i-26.ru/forum/topic.php?id=3776&replies=1#post-6797

http://iheartcity.co.uk/members/usaqdvaki/activity/210373

http://forum.sixvirtues.com/topic/wwwlouisvuittonbeltnycom-qw330333#post-124452

http://www.bizgenie.net/testcontent/members/usamax321/activity/398

http://www.nutriciologia.ru/forum/topic.php?id=1916&replies=1#post-3268

http://forum.flowboard.sg/topic.php?id=8653&replies=1#post-9625

http://todorefrigeracionyaireacondicionado.com/foro/topic.php?id=9179&replies=1#post-10068

http://resortaquarius.com/buzzac/members/usafthaoija/activity/2643

http://ch40s.net/bbpress/topic.php?id=37753&replies=1#post-60706

http://icstarsalum.com/portfolios/542

http://www.endsofearth.com/forum/topic/wwwlouisvuittonhandbagsnyccom-tj550293#post-75161

http://way2freshers.com/discuss/topic/wwwlouisvuittonoutletonlinelovecom-jr660356#post-125448

http://humacon.org/members/usarviost/activity/30829

http://www.relatedstudy.com/blog/view/109221/wwwlouisvuittonbeltnycom-qw330088

Anonymous said...

generic xanax does 1mg xanax do - xanax duration

Anonymous said...

alprazolam xanax xanax uses - taking 4 xanax bars

Anonymous said...

buy tramadol online tramadol 50mg how many to take - tramadol 50mg price

Anonymous said...

buy tramadol online buy tramadol online in europe - buy tramadol direct

Anonymous said...

buy tramadol online life after tramadol addiction - buy tramadol overnight shipping

Anonymous said...

buy carisoprodol carisoprodol and alcohol - carisoprodol 350 mg shelf life

Anonymous said...

xanax online xanax withdrawal vs valium withdrawal - buy xanax cheap online no prescription

Anonymous said...

buy carisoprodol carisoprodol usa no prescription - carisoprodol 350 mg addictive

Anonymous said...

generic xanax xanax overdose cat - taking xanax recreational use

Anonymous said...

xanax online xanax grapefruit - generic xanax bars no imprint

Anonymous said...

alprazolam no prescription .5 xanax high - buy xanax online no prescription mastercard

Anonymous said...

buy tramadol overnight tramadol online doctor consult - buy tramadol online no prescription cod

Anonymous said...

buy generic xanax online generic time release xanax - zoloft for xanax for anxiety

Anonymous said...

buy tramadol online tramadol for high - tramadol online pharmacy

Anonymous said...

buy cialis online generic cialis buy us - cialis 40 mg tablets

Anonymous said...

buy cialis online generic cialis viagra and levitra - buy cialis holland

Anonymous said...

learn how to buy tramdadol tramadol hcl like vicodin - buy 300 mg tramadol

Anonymous said...

tramadol cheap order tramadol cod overnight - tramadol side effects

Anonymous said...

http://landvoicelearning.com/#62431 tramadol for dogs taken by humans - tramadol for dogs to buy

Anonymous said...

http://buytramadolonlinecool.com/#91646 tramadol 100mg buy online - tramadol no prescription legal

Anonymous said...

buy tramadol tramadol overdose and narcan - tramadol online no prescription cheap

Anonymous said...

buy tramadol tramadol 100mg used - tramadol ketorolaco

Anonymous said...

http://reidmoody.com/#36921 ativan drug test - ativan highly addictive

Anonymous said...

http://ranchodelastortugas.com/#50238 xanax online - alprazolam 0.5mg price

Anonymous said...

xanax 1mg maximum xanax dosage one time - xanax drug effects

Anonymous said...

Wow, marvelous blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of your site is excellent, as well as
the content!

Feel free to visit my website; ロレックスレプリカ

Anonymous said...

Fastidious replies in return of this difficulty with genuine arguments and describing everything about that.


Also visit my website; プラダ バッグ

Anonymous said...

Hello! ӏ just want to give you a huge thumbs up for thе eхcellеnt information уou
have hеre on thіs post. Ι will be сoming back to your blog for more soon.


Review my blοg post; raspberry ketone uk

Anonymous said...

magnificent points altogether, you simply gained a new reader.

What would you recommend about your put up that you made some days in
the past? Any certain?

Feel free to visit my website ... ksvbasd.de

Anonymous said...

I read this article completely on the topic of the comparison of newest and earlier
technologies, it's awesome article.

Feel free to surf to my blog - Chaussures De Football Pas Cher