use of org.apache.wicket.util.crypt.SunJceCrypt in project wicket by apache.
the class CryptTest method crypt.
@Test
public void crypt() {
final ICrypt crypt = new SunJceCrypt();
crypt.setKey("someStableKey");
try {
if (crypt.encryptUrlSafe("test") != null) {
final String text = "abcdefghijkABC: A test which creates a '/' and/or a '+'";
final String expectedUrlSafeEncrypted = "xXMS3UMELV--qVINGVFaYaiqUPOtryc_E4x0MyMFgYl-TgTGKxczTzPvwJrE-4YEVMpl-F3eDAg";
final String encrypted = crypt.encryptUrlSafe(text);
assertEquals(expectedUrlSafeEncrypted, encrypted);
assertEquals(text, crypt.decryptUrlSafe(expectedUrlSafeEncrypted));
assertNull(crypt.decryptUrlSafe("style.css"));
}
} catch (Exception ex) {
// fails on JVMs without security provider (e.g. seems to be on
// MAC in US)
}
}
use of org.apache.wicket.util.crypt.SunJceCrypt in project openmeetings by apache.
the class OmAuthenticationStrategy method defaultCrypt.
private static ICrypt defaultCrypt(String encryptionKey, String saltStr) {
SunJceCrypt crypt = null;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos)) {
ps.append(saltStr).append("om_secret");
byte[] salt = Arrays.copyOfRange(baos.toByteArray(), 0, 8);
crypt = new SunJceCrypt(salt, 1000);
crypt.setKey(encryptionKey);
} catch (IOException e) {
log.error("Enxpected error while creating crypt", e);
}
return crypt;
}
Aggregations