Skip to content

Instantly share code, notes, and snippets.

@daler445
Created June 2, 2020 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daler445/070aebbca74c1827910ae7d2c97851ed to your computer and use it in GitHub Desktop.
Save daler445/070aebbca74c1827910ae7d2c97851ed to your computer and use it in GitHub Desktop.
AES/ECB/PKCS5Padding Example
import javax.crypto.*;
import javax.crypto.spec.*;
import java.util.*;
public class main {
public static void main(String[] args) throws Exception {
String keyRaw = "fLVjUa1Sw2Auca6R9VSvLmI0T4OnmgvV";
SecretKeySpec skeySpec = new SecretKeySpec(keyRaw.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal("Value to encrypt".getBytes());
System.out.println(Base64.getEncoder().encodeToString(encrypted));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment