-
Notifications
You must be signed in to change notification settings - Fork 0
/
cipher.java
30 lines (23 loc) · 1.05 KB
/
cipher.java
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
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import javax.security.auth.login.LoginException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
public class cipher {
public static void main(String[]args) throws LoginException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
System.out.println("Enter the string: ");
Scanner In = new Scanner(System.in);
String str = In.nextLine();
Cipher cipher = Cipher.getInstance("AES");
SecretKeySpec key = new SecretKeySpec("0D485016A0746C49A138D44670EA899F".getBytes(), "AES");
cipher.init(Cipher.ENCRYPT_MODE,key);
byte[] bytes = cipher.doFinal(str.getBytes());
for(byte b : bytes){
System.out.print(b);
}
}
}