這是本文件的舊版!
Jasypt With Properties File
How to?
@Test public void test() throws IOException{ StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); encryptor.setPassword("jasypt"); Properties p = new Properties(); p.setProperty("account", "root"); p.setProperty("password", PropertyValueEncryptionUtils.encrypt("123456", encryptor)); File file = new File("test.properties"); file.createNewFile(); FileOutputStream fos = null; try { fos = new FileOutputStream(file); p.store(fos, "gg"); } finally { close(fos); } EncryptableProperties ep = new EncryptableProperties(encryptor); FileInputStream fis = null; try { fis = new FileInputStream(file); ep.load(fis); } finally { close(fis); } Assert.assertEquals("root", ep.getProperty("account")); Assert.assertEquals("123456", ep.getProperty("password")); }