-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.java
More file actions
49 lines (44 loc) · 1.65 KB
/
Copy pathdecrypt.java
File metadata and controls
49 lines (44 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* For this to work, you must have the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy in your Java install.
*
*/
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
class decrypt {
public static byte[] KEY = DatatypeConverter.parseHexBinary("4E9906E8FCB66CC9FAF49310620FFEE8F496E806CC057990209B09A433B66C1B");
public static String CIPHERTEXT = "j1Uyj3Vx8TY9LtLZil2uAuZkFQA/4latT76ZwgdHdhw";
public void run()
{
try
{ // Create key and cipher
String padding = new String("");
for (int i = 0; i <= ((4 - CIPHERTEXT.length() % 4) -1); i++){
padding += "=";
}
byte[] decodedValue = DatatypeConverter.parseBase64Binary(CIPHERTEXT + padding);
String password = new String(decodedValue, StandardCharsets.UTF_8);
Key aesKey = new SecretKeySpec(KEY, "AES");
Cipher cipher = Cipher.getInstance("AES");
// encrypt the text
cipher.init(Cipher.ENCRYPT_MODE, aesKey);
byte[] encrypted = cipher.doFinal(password.getBytes());
System.out.println(new String(encrypted));
// decrypt the text
cipher.init(Cipher.DECRYPT_MODE, aesKey);
String decrypted = new String(cipher.doFinal(encrypted));
System.out.println(decrypted);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
decrypt pass = new decrypt();
pass.run();
}
}