-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlowfishTest.java
More file actions
34 lines (28 loc) · 1.24 KB
/
BlowfishTest.java
File metadata and controls
34 lines (28 loc) · 1.24 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
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.lang.*;
import java.util.*;
public class BlowfishTest {
private static Random random = new Random((new Date()).getTime());
public static void main(String[] args) throws Exception {
String enc = encrypt("qwerty1993");
System.out.println(enc);
decrypt(enc);
}
private static String encrypt(String password) throws Exception {
byte[] keyData = (password).getBytes();
SecretKeySpec secretKeySpec = new SecretKeySpec(keyData, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
byte[] hasil = cipher.doFinal(password.getBytes());
return new String(Base64.getEncoder().encode(hasil));
}
private static void decrypt(String dec) throws Exception {
byte[] keyData = ("qwerty1993").getBytes();
SecretKeySpec secretKeySpec = new SecretKeySpec(keyData, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
byte[] hasil = cipher.doFinal(Base64.getDecoder().decode(dec));
System.out.println(new String(hasil));
}
}