Using the Rijndael algorithm, is it possible to encrypt the configuration file (or section in the configuration file) and then decrypt this file in Java? Assumptions can be made, for example:
- Transition to IV (non-auto-generated idea :: GenerateIV ();)
- Hand over the key
- BlockSize - 128 (standard)
Assuming this can be done, my next question on this is:
- Can keySize be 256? I know 128 is AES, but we would like to use 256. I also donβt know if Java has this provider for 256 or if I need to use BouncyCastle
- What is a gasket? PKCS7?
- I assume CiperMode will be CBC
Something like this in C #? But there is no clue if it can be decrypted in Java ... maybe even my C # is wrong?
public static void initCrypt() { byte[] keyBytes = System.Text.UTF8Encoding.UTF8.GetBytes("abcdefghijklmnop"); rijndaelCipher = new RijndaelManaged(); PasswordDeriveBytes pdb = new PasswordDeriveBytes(keyBytes, new SHA1CryptoServiceProvider().ComputeHash(keyBytes)); byte[] key = pdb.GetBytes(32); byte[] iv = pdb.GetBytes(16); rijndaelCipher.Mode = CipherMode.CBC; rijndaelCipher.Padding = PaddingMode.PKCS7;
yantwill
source share