c# - Generate key using Pass Phrase or AesCryptoServiceProvider? -


we using aes encryption encrypt data. generating key once in year using app(i.e console) way have choose generate key?

1. need generate key using pass phrase method?

2. or have choose default generate key provided aescryptoserviceprovider?

the below method uses pass phrase generating encryption.

method 1:

private static readonly byte[] salt = new byte[] { 10, 20, 30, 40, 50, 60, 70, 80 };  private static byte[] createkey(string password, int keybytes = 32) {     const int iterations = 300;     var keygenerator = new rfc2898derivebytes(password, salt, iterations);     return convert.frombase64string(keygenerator.getbytes(keybytes)); } 

the below method uses aescryptoserviceprovider generating key , didn't use pass phrase

method 2:

var key = default(string);  using (var provider = new aescryptoserviceprovider()) {     provider.generatekey();     key = system.text.encoding.ascii.getstring(provider.key); } 

edit:

can use random number generation method?

public static byte[] randomnumbergenerator() {   var rngbytes = new byte[32];   using (randomnumbergenerator objnumbergenerator = new rngcryptoserviceprovider())   {     objnumbergenerator.getbytes(rngbytes);     return rngbytes;   }  } 


Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -