-3

I earlier found this answer regarding hashing passwords in Java, but I'm using Java 7 while the answer works only in Java 8. I tried to adapt it without success, so... Any suggestions? I also downloaded the bouncycastle library, but I don't understand how it works...

Thank you for your time

EMENCII
  • 1
  • 4
  • Possible duplicate of [How can I hash a password in Java?](https://stackoverflow.com/questions/2860943/how-can-i-hash-a-password-in-java) – Ravi Oct 02 '17 at 11:27
  • I have already seen it, but I am unsure about how I can use the code posted there in Java 7... @Ravi – EMENCII Oct 02 '17 at 11:30
  • Looked through the code of the linked question. I didn't find any Java 8 specific syntax. I think you can use these methods with some caution in respect to the availablility of some crypto algos. – blafasel Oct 02 '17 at 11:31
  • It is clearly mentioned in accepted answer **The SunJCE in Java 6 supports PBKDF2, which is a good algorithm to use for password hashing** – Ravi Oct 02 '17 at 11:33
  • @blafasel java.util.Base64 is not recognized... – EMENCII Oct 02 '17 at 11:37
  • @Ravi PBKDF2 is not recognised... And importing com.sun.crypto.provider.SunJCE doesn't work, because it doesn't exist – EMENCII Oct 02 '17 at 11:39
  • Take [Apache commons Base64](https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64.html). Or take the Sun implementation (`sun.misc.somewhat`). And get your JCE problems fixed. – blafasel Oct 02 '17 at 11:44

1 Answers1

0

I would suggest using Jasypt it very simple to use.

For example:

private static final String ENC_ALGORITHM = "PBEWithMD5AndDES";
...
StandardPBEStringEncryptor textEncryptor = new StandardPBEStringEncryptor();
textEncryptor.setAlgorithm(ENC_ALGORITHM);
textEncryptor.setPassword("MySuperSecretSeed"); // make sure this is stored somewhere safe like an ENV variable
String encryptedPassword = textEncryptor.encrypt("Password to be encrypted");
nuvio
  • 2,555
  • 4
  • 32
  • 58