/** * Default constructor that initializes a {@link DefaultSerializer} as the {@link #getSerializer() serializer} and * an {@link AesCipherService} as the {@link #getCipherService() cipherService}. */ public AbstractRememberMeManager() { this.serializer = new DefaultSerializer<PrincipalCollection>(); AesCipherService cipherService = new AesCipherService(); this.cipherService = cipherService; setCipherKey(cipherService.generateNewKey().getEncoded()); }
public ShiroSecurityTokenInjector() { this.passPhrase = bits128; // Set up AES encryption based cipher service, by default cipherService = new AesCipherService(); }
public byte[] encrypt(byte[] plaintext, final byte[] key) { AesCipherService cipher = new AesCipherService(); cipher.setMode(OperationMode.ECB); cipher.setPaddingScheme(PaddingScheme.NONE); byte[] paddedPlaintext = padding.padPkcsN7(plaintext, getBlockSize()); ByteSource ciphertext = cipher.encrypt(paddedPlaintext, key); return ciphertext.getBytes(); }
public byte[] decrypt(byte[] ciphertext, final byte[] key) { AesCipherService cipher = new AesCipherService(); cipher.setMode(OperationMode.ECB); cipher.setPaddingScheme(PaddingScheme.NONE); ByteSource plaintext = cipher.decrypt(ciphertext, key); return padding.removePadding(plaintext.getBytes()); }
Key key = new AesCipherService().generateNewKey(128); AesCipherService cipher = new AesCipherService(); for (int i = 0; i <20; ++i) { System.out.println(Hex.encode(cipher.encrypt("abcde".getBytes(StandardCharsets.UTF_8), key.getEncoded()).getBytes())); }
AesCipherService cipherService = new AesCipherService(); try { List<GenericValue> rows = EntityQuery.use(delegator).from("EntityKeyStore").queryList(); Debug.logInfo("Decrypting with old key: " + oldKey, module); try { keyBytes = cipherService.decrypt(keyBytes, Base64.decodeBase64(oldKey)).getBytes(); } catch(Exception e) { Debug.logInfo("Failed to decrypt with Shiro cipher; trying with old cipher", module); if (newKey != null) { Debug.logInfo("Encrypting with new key: " + oldKey, module); newKeyText = cipherService.encrypt(keyBytes, Base64.decodeBase64(newKey)).toBase64(); } else { newKeyText = Base64.encodeBase64String(keyBytes);
import org.apache.commons.codec.binary.Base64; import org.apache.shiro.crypto.AesCipherService; public class Test { public static void main(String[] args) throws Exception { System.out.println(encrypt("Hello")); } static String encrypt(String input) throws Exception { AesCipherService aesCipher = new AesCipherService(); aesCipher.setModeName("ECB"); byte[] bytes = aesCipher.encrypt(input.getBytes("UTF-8"), "0123456789abcdef".getBytes()).getBytes(); byte[] bytesEncoded = Base64.encodeBase64(bytes); return new String(bytesEncoded); } }
private static byte[] decrypt(Key key, byte[] ciphertext) { AesCipherService cipherService = new AesCipherService(); ByteSource plainText = cipherService.decrypt(ciphertext, key.getEncoded()); return plainText.getBytes(); }
public AES(byte[] key) { super(); this.key = key; cipher = new AesCipherService(); cipher.setMode(OperationMode.ECB); cipher.setPaddingScheme(PaddingScheme.NONE); }
protected ShiroStorageHandler(byte[] kek) { hashService = new DefaultHashService(); cipherService = new AesCipherService(); cipherService.setMode(OperationMode.ECB); saltedCipherService = new AesCipherService(); this.kek = kek; }
@Override public byte[] encrypt(byte[] rawBytes) { if (rawBytes == null) { return null; } else { return aesCipherService.encrypt(rawBytes, key).getBytes(); } } }
@Override protected byte[] decryptValue(byte[] key, EncryptMethod encryptMethod, String encryptedString) throws GeneralException { switch (encryptMethod) { case SALT: return saltedCipherService.decrypt(Base64.decodeBase64(encryptedString), key).getBytes(); default: return cipherService.decrypt(Base64.decodeBase64(encryptedString), key).getBytes(); } }
@Override protected Key generateNewKey() { return saltedCipherService.generateNewKey(); }
public ShiroSecurityPolicy() { this.passPhrase = bits128; // Set up AES encryption based cipher service, by default cipherService = new AesCipherService(); permissionsList = new ArrayList<>(); rolesList = new ArrayList<>(); alwaysReauthenticate = true; }
/** * Encrypts the given text using all Shiro defaults: 128 bit size, CBC mode, PKCS5 padding scheme. * * @param key The key to use * @param initialText The text to encrypt * @return The encrypted text */ private static byte[] encrypt(Key key, byte[] initialText) { AesCipherService cipherService = new AesCipherService(); ByteSource cipherText = cipherService.encrypt(initialText, key.getEncoded()); return cipherText.getBytes(); }
@Override public byte[] encrypt(byte[] rawBytes) { if (rawBytes == null) { return null; } else { return aesCipherService.encrypt(rawBytes, key).getBytes(); } } }
@Override public byte[] decrypt(byte[] encryptedBytes) { if (encryptedBytes == null) { return null; } else { return aesCipherService.decrypt(encryptedBytes, key).getBytes(); } }
@Override public byte[] decode(final byte[] value) { try { final byte[] verifiedValue = verifySignature(value); final Key key = new SecretKeySpec(this.encryptionSecretKey.getBytes(UTF8_ENCODING), this.secretKeyAlgorithm); final CipherService cipher = new AesCipherService(); final byte[] result = cipher.decrypt(verifiedValue, key.getEncoded()).getBytes(); return result; } catch (final Exception e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
/** * Default constructor that initializes a {@link DefaultSerializer} as the {@link #getSerializer() serializer} and * an {@link AesCipherService} as the {@link #getCipherService() cipherService}. */ public AbstractRememberMeManager() { this.serializer = new DefaultSerializer<PrincipalCollection>(); AesCipherService cipherService = new AesCipherService(); this.cipherService = cipherService; setCipherKey(cipherService.generateNewKey().getEncoded()); }
@Override protected String encodeKey(byte[] key) throws GeneralException { if (kek != null) { return saltedCipherService.encrypt(key, kek).toBase64(); } else { return Base64.encodeBase64String(key); } }