简体   繁体   中英

Symmetric AES Encryption and Decryption returning same value on any Java versions and supporting Java 6 and with out using any external libraries

I want to get the same encrypted value on any version of Java and the code should support the Java 6 and with out using any external libraries. I am new to Java and Cryptography. I really appreciate it someone help. Thanks in advance.

If you encrypt the same plaintext with the same key multiple times, you're supposed to get different results. This is a security property and is due to randomized initialization vectors or nonces.

The only popular mode of operation that doesn't use an IV or a nonce is the ECB mode which is available in all Java versions. If you use that mode, you will always get the same result across all versions of Java.

ECB mode is not very secure and should not be used.

If you simply need an implementation that is compatible across many versions of Java, then you could just use JNCryptor . It is very secure. Since you cannot compare the ciphertexts of a randomized mode, you will need to encrypt in one Java version and decrypt in another (don't forget the other direction).

without using any external libraries

Cryptography is hard and you said that you're new to cryptography. You need to use vetted and secure libraries instead of trying to write your own, if you want to use it for more than learning. Libraries are there to help you produce more secure code.

Of course, most libraries are open source, so you could just copy their code into your project and then you don't have any dependencies, but before you do this, check if this is compatible with the license of the library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM