Search in sources :

Example 1 with SunJceCrypt

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)
    }
}
Also used : ICrypt(org.apache.wicket.util.crypt.ICrypt) SunJceCrypt(org.apache.wicket.util.crypt.SunJceCrypt) Test(org.junit.Test)

Example 2 with SunJceCrypt

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;
}
Also used : PrintStream(java.io.PrintStream) SunJceCrypt(org.apache.wicket.util.crypt.SunJceCrypt) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

SunJceCrypt (org.apache.wicket.util.crypt.SunJceCrypt)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ICrypt (org.apache.wicket.util.crypt.ICrypt)1 Test (org.junit.Test)1