Created
June 2, 2020 08:26
-
-
Save daler445/070aebbca74c1827910ae7d2c97851ed to your computer and use it in GitHub Desktop.
AES/ECB/PKCS5Padding Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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