static void Main(string[] args) { using (var rijndael = new RijndaelManaged()) using (var hmacsha256 = new HMACSHA256()) { rijndael.GenerateKey(); hmacsha256.Initialize(); Console.WriteLine(template, new SoapHexBinary(rijndael.Key), new SoapHexBinary(hmacsha256.Key)); } Console.WriteLine("press any key to exit..."); Console.ReadKey(); }
/// -------------- Two Utility Methods (not used but may be useful) ----------- /// Generates an encryption key. public static byte[] GenerateEncryptionKey() { //Generate a Key. RijndaelManaged rm = new RijndaelManaged(); rm.GenerateKey(); return rm.Key; }
public static byte[] GenerateKey() { using (RijndaelManaged myRijndael = new RijndaelManaged()) { myRijndael.GenerateKey(); return(myRijndael.Key); } }
public static string GetNewK() { //Create a new key and initialization vector. _SymmetricAlgorithm.GenerateKey(); _SymmetricAlgorithm.GenerateIV(); return(string.Concat(Convert.ToBase64String(_SymmetricAlgorithm.Key), "$", Convert.ToBase64String(_SymmetricAlgorithm.IV))); }
public static byte[] GenerateKey() { var oAlgorithm = new RijndaelManaged(); oAlgorithm.GenerateKey(); return(oAlgorithm.Key); }
public SimpleAES(int keySize) { rm = new RijndaelManaged(); rm.Mode = CipherMode.CBC; rm.KeySize = keySize; rm.GenerateKey(); encoder = new UTF8Encoding(); }
public static byte[] RandomKey(int length) { var alg = new RijndaelManaged(); alg.KeySize = length * 8; alg.GenerateKey(); return(alg.Key); }
public void CreateSymmetricKey() { symmetricAlgo = (RijndaelManaged)RijndaelManaged.Create(); symmetricAlgo.GenerateKey(); encryptedKey = ProtectedData.Protect(symmetricAlgo.Key, null, DataProtectionScope.CurrentUser); stream = new MemoryStream(); }
/// -------------- Two Utility Methods (not used but may be useful) ----------- /// Generates an encryption key. static public byte[] GenerateEncryptionKey() { //Generate a Key. RijndaelManaged rm = new RijndaelManaged(); rm.GenerateKey(); return(rm.Key); }
public static string GenerateKey() { RijndaelManaged cryptor = new RijndaelManaged(); cryptor.GenerateKey(); return(Convert.ToBase64String(cryptor.Key)); }
public static byte[] GenerateKey() { RijndaelManaged algo = new RijndaelManaged(); algo.KeySize = 256; algo.GenerateKey(); return(algo.Key); }
public static KeyNIvSet GenerateKey() { RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.GenerateKey(); rijndaelManaged.GenerateIV(); return(new KeyNIvSet(rijndaelManaged.Key, rijndaelManaged.IV)); }
public static byte[] GenerateKey() { var rm = new RijndaelManaged(); rm.GenerateKey(); return(rm.Key); }
/// <summary> /// AES算法构造函数(KEY和IV随机生成) /// </summary> public AES() { aes = new RijndaelManaged(); aes.GenerateKey(); aes.GenerateIV(); Key = Convert.ToBase64String(aes.Key); IV = Convert.ToBase64String(aes.IV); }
private static void RdGenerateSecretKey(RijndaelManaged rdProvider) { if (savedKey == null) { rdProvider.KeySize = 256; rdProvider.GenerateKey(); savedKey = rdProvider.Key; } }
private RijndaelManaged GetCryptographer() { RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.KeySize = 128; rijndaelManaged.GenerateIV(); rijndaelManaged.GenerateKey(); return(rijndaelManaged); }
public static byte[] GenerateKey() { RijndaelManaged rijndaelCipher = new RijndaelManaged(); rijndaelCipher.KeySize = 128; rijndaelCipher.GenerateKey(); return(rijndaelCipher.Key); }
public static string MakeKey() { RijndaelManaged provider = new RijndaelManaged(); provider.GenerateKey(); byte[] keyData = provider.Key; return(Convert.ToBase64String(keyData)); }
protected void JS_btn_Submit_Click(object sender, EventArgs e) { //string simple = HttpUtility.HtmlEncode(JS_tbFName.Text); //Response.Write(simple); //HttpUtility.HtmlEncode(JS_tbEmailAddr.Text); //HttpUtility.HtmlEncode(tb_pwd.Text); //HttpUtility.HtmlEncode(tb_cfpwd.Text); if (JS_tbFName.Text == "" || JS_tbLName.Text == "" || JS_tbCCInfo.Text == "" || JS_tbEmailAddr.Text == "" || JS_tbDOB.Text == "" || tb_cfpwd.Text == "" || tb_pwd.Text == "") { bool validInput = JS_ValidateInput(); } else if (tb_cfpwd.Text != tb_pwd.Text) { lbMismatchPwd.Text = "Password Mismatch!"; } else if (tb_cfpwd.Text == tb_pwd.Text || JS_tbFName.Text != "" || JS_tbLName.Text != "" || JS_tbCCInfo.Text != "" || JS_tbEmailAddr.Text != "" || JS_tbDOB.Text != "" || tb_cfpwd.Text != "" || tb_pwd.Text != "") { if (JS_checkemail() == true) { lbEmailExisted.Text = "Email already existed!"; } else if (tb_cfpwd.Text == tb_pwd.Text || JS_tbFName.Text != "" || JS_tbLName.Text != "" || JS_tbCCInfo.Text != "" || JS_tbEmailAddr.Text != "" || JS_tbDOB.Text != "" || tb_cfpwd.Text != "" || tb_pwd.Text != "" || JS_checkemail() == false) { //string pwd = get value from your Textbox string pwd = tb_pwd.Text.ToString().Trim(); //Generate random "salt" RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] saltByte = new byte[8]; //Fills array of bytes with a cryptographically strong sequence of random values. rng.GetBytes(saltByte); salt = Convert.ToBase64String(saltByte); SHA512Managed hashing = new SHA512Managed(); string pwdWithSalt = pwd + salt; byte[] plainHash = hashing.ComputeHash(Encoding.UTF8.GetBytes(pwd)); byte[] hashWithSalt = hashing.ComputeHash(Encoding.UTF8.GetBytes(pwdWithSalt)); finalHash = Convert.ToBase64String(hashWithSalt); RijndaelManaged cipher = new RijndaelManaged(); cipher.GenerateKey(); Key = cipher.Key; IV = cipher.IV; createAccount(); Response.Redirect("login.aspx"); } } }
public KeyVectorPair() { RijndaelManaged rm = new RijndaelManaged(); rm.GenerateKey(); rm.GenerateIV(); this.Key = Convert.ToBase64String(rm.Key); this.IV = Convert.ToBase64String(rm.IV); }
public void GenerateKey(out string key, out string iv) { using (RijndaelManaged managed = new RijndaelManaged()) { managed.GenerateKey(); key = Convert.ToBase64String(managed.Key); iv = Convert.ToBase64String(managed.IV); } }
private void RdGenerateSecretKey(RijndaelManaged _provider) { if (m_SavedKey == null) { _provider.KeySize = 256; _provider.GenerateKey(); m_SavedKey = _provider.Key; } }
public static string Decrypt(byte[] encryptedString) { using (var myRijndael = new RijndaelManaged()) { myRijndael.GenerateKey(); myRijndael.GenerateIV(); return(DecryptStringFromBytes(encryptedString, myRijndael.Key, myRijndael.IV)); } }
static string GenerateNewKey() { using (var rijndael = new RijndaelManaged()) { rijndael.GenerateKey(); return(Convert.ToBase64String(rijndael.Key)); } }
public static byte[] Encrypt(string unencryptedString) { using (var myRijndael = new RijndaelManaged()) { myRijndael.GenerateKey(); myRijndael.GenerateIV(); return(EncryptStringToBytes(unencryptedString, myRijndael.Key, myRijndael.IV)); } }
static void Main(string[] args) { RijndaelManaged aes = new RijndaelManaged() { KeySize = 256, Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 }; aes.GenerateKey(); aes.GenerateIV(); MySqlConnection connection = new MySqlConnection("Server = " + ServerIP + "; Port = 3306; Database = document_center; Uid = root; Pwd = kit2020"); try { connection.Open(); string command = "SELECT MAX(expire_date) FROM crypto_key;"; MySqlDataAdapter adapter = new MySqlDataAdapter(command, connection); DataSet data = new DataSet(); adapter.Fill(data); if (data.Tables[0].Rows.Count != 1) { return; } string tmp = data.Tables[0].Rows[0]["MAX(expire_date)"].ToString(); DateTime date = new DateTime(); if (tmp == string.Empty) { date = DateTime.Now; } else { date = DateTime.Parse(tmp); } string apply_date = date.ToString("yyyy-MM-dd"); date = date.AddYears(1); string expire_date = date.ToString("yyyy-MM-dd"); command = "INSERT INTO crypto_key VALUES( @key, @iv, '" + apply_date + "', '" + expire_date + "', 30);"; MySqlCommand commander = new MySqlCommand(command, connection); commander.Parameters.AddWithValue("key", aes.Key); commander.Parameters.AddWithValue("iv", aes.IV); if (commander.ExecuteNonQuery() != 1) { return; } } catch (Exception ex) { }; if (connection.State != ConnectionState.Closed) { connection.Close(); } }
private byte[] generiraj_kljuc() { generiraj = new RijndaelManaged(); imamo_kljuc = true; generiraj.KeySize = dolzina_kljuca_AES; generiraj.GenerateKey(); return(generiraj.Key); }
/// <summary> /// Generates a random 1024 bit Rijndael key with PKCS7 padding mode and a 16 byte initiatlization vector /// </summary> /// <returns></returns> public byte[] GetRandomRijndaelKey() { RijndaelManaged RIJ = new RijndaelManaged(); RIJ.Padding = PaddingMode.PKCS7; RIJ.IV = new byte[16]; RIJ.GenerateKey(); return(RIJ.Key); }
static void SetKey() { _rijndael.GenerateKey(); using (FileStream writeNewKeyStream = File.Create(_keyFilePath)) writeNewKeyStream.Write(_rijndael.Key, 0, _rijndael.Key.Length); _Key = _rijndael.Key; }
public string GenerateKey() { SymmetricAlgorithm symmetricAlgorithm = new RijndaelManaged(); symmetricAlgorithm.KeySize = 128; symmetricAlgorithm.GenerateKey(); return(Convert.ToBase64String(symmetricAlgorithm.Key)); }
public int Create() { int result = 0; string MyDB = ConfigurationManager.ConnectionStrings["Database"].ConnectionString; RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] saltbyte = new byte[8]; rng.GetBytes(saltbyte); string salt = Convert.ToBase64String(saltbyte); SHA512Managed hashing = new SHA512Managed(); string pwd = password + salt; byte[] plainHash = hashing.ComputeHash(Encoding.UTF8.GetBytes(password)); byte[] hashWithSalt = hashing.ComputeHash(Encoding.UTF8.GetBytes(pwd)); string finalHash = Convert.ToBase64String(hashWithSalt); RijndaelManaged cipher = new RijndaelManaged(); cipher.GenerateKey(); byte[] Key = cipher.Key; byte[] IV = cipher.IV; try { using (SqlConnection con = new SqlConnection(MyDB)) { using (SqlCommand cmd = new SqlCommand("INSERT INTO Account (FName, LName, Email, PasswordHash, PasswordSalt, Dob, CNo, CVV) VALUES(@FName,@LName, @Email, @PasswordHash, @PasswordSalt, @DoB, @CNo, @CVV)")) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@FName", fname); cmd.Parameters.AddWithValue("@LName", lname); cmd.Parameters.AddWithValue("@Email", email); cmd.Parameters.AddWithValue("@PasswordHash", finalHash); cmd.Parameters.AddWithValue("@PasswordSalt", salt); cmd.Parameters.AddWithValue("@DoB", DateTime.Now); cmd.Parameters.AddWithValue("@CNo", encryptData(cno, Key, IV)); cmd.Parameters.AddWithValue("@CVV", encryptData(cvv.ToString(), Key, IV)); cmd.Connection = con; con.Open(); SqlCommand sqlCmd = new SqlCommand("INSERT INTO Pass_Hist (Id) VALUES ((SELECT Id FROM Account WHERE Email=@Email))"); sqlCmd.Parameters.AddWithValue("@Email", email); sqlCmd.Connection = con; result = cmd.ExecuteNonQuery(); sqlCmd.ExecuteNonQuery(); con.Close(); } } } } catch (Exception ex) { throw new Exception(ex.ToString()); } return(result); }
/// <summary> /// Inits the cipher. /// </summary> /// <returns></returns> private RijndaelManaged InitCipher() { RijndaelManaged cipher = CreateCipher(); //GenerateKey method utilises the RNGCryptoServiceProvider //class to generate random bytes of necessary length cipher.GenerateKey(); return(cipher); }