Cryptage config.properties avec Jasypt
Bonjour,
Encore débutant en Java, je cherche un moyen de crypter une chaîne dans un fichier properties.
J'ai trouvé la librairie Jasypt http://www.jasypt.org/ qui m'a l'air robuste et abordable.
J'ai créé un classe pour faire un test de cryptage d'une chaîne sans succès :
Ma classe
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
package nested;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.properties.EncryptableProperties;
/**
*
* @author seb
*/
public class config {
//public static String readCfg(String PBEPwd) {
public static void main(String[] args) {
String cfgFile = "config.properties";
String essPwd = null;
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
//encryptor.setPassword(PBEPwd);
encryptor.setPassword("localhost");
Properties props = new EncryptableProperties(encryptor);
try {
props.load(new FileInputStream(cfgFile));
essPwd = props.getProperty("user.pwd");
} catch (IOException ex) {
Logger.getLogger(config.class.getName()).log(Level.SEVERE, null, ex);
}
//return essPwd;
System.out.println(essPwd);
}
} |
Mon fichier properties
Code:
1 2
|
user.pwd=ENC(j85OIxhBQ5VYKwTqi5tCRbCF2tQj+5g7) |
Les erreurs
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
run:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at nested.config.main(config.java:28)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds) |
Merci d'avance pour toute info! Maintenant s'il y a un moyen plus simple et tout autant sécurisé je suis preneur.
SebRoux