encryption - AES How many bits should be ? (I'am learning) -
i'am research encryption aes find library , use that. , did crpyto data there things not understand
edit(15 09 2017) : sorry.. english bad im using translator words not tell want ask.. mean i'am trying learning aes encryption , find code want ask question method sorry english , have not learned yet (:
i sharing codes please tell me crypto method
- how many bits ?
- key random ?
- key how many bits ?
- how store generated key ?
i'am new yet please explenatory thank !
private static byte[] encryptstringtobytes_aes(string plaintext, byte[] key) { byte[] encrypted; byte[] iv; using (aes aesalg = aes.create()) { aesalg.key = key; aesalg.generateiv(); iv = aesalg.iv; aesalg.mode = ciphermode.cbc; var encryptor = aesalg.createencryptor(aesalg.key, aesalg.iv); using (var msencrypt = new memorystream()) { using (var csencrypt = new cryptostream(msencrypt, encryptor, cryptostreammode.write)) { using (var swencrypt = new streamwriter(csencrypt)) { swencrypt.write(plaintext); } encrypted = msencrypt.toarray(); } } } var combinedivct = new byte[iv.length + encrypted.length]; array.copy(iv, 0, combinedivct, 0, iv.length); array.copy(encrypted, 0, combinedivct, iv.length, encrypted.length); return combinedivct; }
private static string decryptstringfrombytes_aes(byte[] ciphertextcombined, byte[] key) { string plaintext = null; using (aes aesalg = aes.create()) { aesalg.key = key; byte[] iv = new byte[aesalg.blocksize / 8]; byte[] ciphertext = new byte[ciphertextcombined.length - iv.length]; array.copy(ciphertextcombined, iv, iv.length); array.copy(ciphertextcombined, iv.length, ciphertext, 0, ciphertext.length); aesalg.iv = iv; aesalg.mode = ciphermode.cbc; icryptotransform decryptor = aesalg.createdecryptor(aesalg.key, aesalg.iv); using (var msdecrypt = new memorystream(ciphertext)) { using (var csdecrypt = new cryptostream(msdecrypt, decryptor, cryptostreammode.read)) { using (var srdecrypt = new streamreader(csdecrypt)) { plaintext = srdecrypt.readtoend(); } } } } return plaintext; }
how many bits shold use ?
Comments
Post a Comment