@Override public byte[] encrypt(byte[] rawBytes) { if (rawBytes == null) { return null; } else { return aesCipherService.encrypt(rawBytes, key).getBytes(); } } }
@Override public byte[] encrypt(byte[] rawBytes) { if (rawBytes == null) { return null; } else { return aesCipherService.encrypt(rawBytes, key).getBytes(); } } }
@Override protected String encodeKey(byte[] key) throws GeneralException { if (kek != null) { return saltedCipherService.encrypt(key, kek).toBase64(); } else { return Base64.encodeBase64String(key); } }
public byte[] encrypt(byte[] plaintext) { ByteSource ciphertext = cipher.encrypt(plaintext, key); return ciphertext.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())); }
/** * 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(); }
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); } }
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(); }
if (newKey != null) { Debug.logInfo("Encrypting with new key: " + oldKey, module); newKeyText = cipherService.encrypt(keyBytes, Base64.decodeBase64(newKey)).toBase64(); } else { newKeyText = Base64.encodeBase64String(keyBytes);