Created
September 5, 2020 14:19
-
-
Save sandermvanvliet/1e5c0143d5a7272105030139e927811f to your computer and use it in GitHub Desktop.
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.BadPaddingException; | |
import javax.crypto.Cipher; | |
import javax.crypto.IllegalBlockSizeException; | |
import javax.crypto.NoSuchPaddingException; | |
import javax.crypto.spec.GCMParameterSpec; | |
import javax.crypto.spec.SecretKeySpec; | |
import java.security.InvalidAlgorithmParameterException; | |
import java.security.InvalidKeyException; | |
import java.security.NoSuchAlgorithmException; | |
import java.util.Base64; | |
public class Main { | |
public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { | |
Cipher c = Cipher.getInstance("AES/GCM/NoPadding"); | |
byte[] ivBuffer = new byte[0xc]; | |
byte[] keyBytes = new byte[] { | |
0x63, | |
0x39, | |
0x30, | |
0x61, | |
0x66, | |
0x30, | |
0x35, | |
0x37, | |
0x65, | |
0x32, | |
0x35, | |
0x37, | |
0x34, | |
0x61, | |
0x66, | |
0x30, | |
0x39, | |
0x37, | |
0x37, | |
0x33, | |
0x66, | |
0x65, | |
0x35, | |
0x37, | |
0x34, | |
0x63, | |
0x65, | |
0x39, | |
0x35, | |
0x34, | |
0x37, | |
0x30, | |
}; | |
try { | |
java.util.Base64.Decoder decoder = Base64.getDecoder(); | |
byte[] decodedBytes = decoder.decode(args[0]); | |
System.arraycopy(decodedBytes, 0, ivBuffer, 0, 0xc); | |
byte[] encryptedBytes = new byte[decodedBytes.length - 0xc]; | |
System.arraycopy(decodedBytes, 12, encryptedBytes,0, decodedBytes.length - 0xc); | |
GCMParameterSpec parameterSpec = new GCMParameterSpec(0x60, ivBuffer); | |
SecretKeySpec keySpec = new javax.crypto.spec.SecretKeySpec(keyBytes, "AES"); | |
c.init(javax.crypto.Cipher.DECRYPT_MODE, keySpec, parameterSpec); | |
byte[] decryptedBytes = c.doFinal(encryptedBytes); | |
String decrypted = new String(decryptedBytes); | |
System.out.println("encrypted: " + args[0] + ", decrypted: " + decrypted); | |
} | |
catch(Exception e) | |
{ | |
System.out.println(e.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment