SecureIdentityLoginCoder.jar
0.00MB
Usage: java -jar SecureIdentityLoginCoder.jar -e|-d string
-e will encode the string
-d will decode the string

알고리즘 "Blowfish"
암호화
$ java -jar SecureIdentityLoginCoder.jar -e 'test'
48e90df5bc00051e
복호화
$ java -jar SecureIdentityLoginCoder.jar -d '48e90df5bc00051e'
test
DecodeIdentity.java
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
public class DecodeIdentity {
private static String encode(String secret) throws NoSuchPaddingException, NoSuchAlgorithmException,InvalidKeyException, BadPaddingException, IllegalBlockSizeException{
byte[] kbytes = "jaas is the way".getBytes();
SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encoding = cipher.doFinal(secret.getBytes());
BigInteger n = new BigInteger(encoding);
return n.toString(16);
}
private static char[] decode(String secret)throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException{
byte[] kbytes = "jaas is the way".getBytes();
SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");
BigInteger n = new BigInteger(secret, 16);
byte[] encoding = n.toByteArray();
if (encoding.length % 8 != 0){
int length = encoding.length;
int newLength = ((length / 8) +1) * 8;
int pad = newLength - length; //number of leading zeros
byte[] old = encoding;
encoding = new byte[newLength];
for (int i = old.length - 1; i>= 0; i--){
encoding[i + pad] = old[i];
}
if (n.signum() == -1){
for (int i = 0; i < newLength - length; i++){
encoding[i] = (byte) -1;
}
}
}
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decode = cipher.doFinal(encoding);
return new String(decode).toCharArray();
}
public static void main(String[] args) throws Exception{
if(args.length ==2){
if (args[0].equals("encode")){
String encode = encode(args[1]);
System.out.println("Encoded password: " + encode);
}else if (args[0].equals("decode")){
System.out.println(decode(args[1]));
}else{
System.out.println("Function not defined");
}
}
}
}'WAS > wildfly' 카테고리의 다른 글
| 메모리 사용율 확인하기 (0) | 2023.05.04 |
|---|---|
| [wildfly] 관리자 페이지 접근 못하게 설정 (0) | 2022.11.26 |
| [wildfly] jboss-cli.sh 접속 스크립트 (0) | 2022.09.06 |
| [wildfly] 기동이슈 (0) | 2022.09.06 |
| [wildfly] jboss-cli.sh 를 통하여 설정, 디폴트 값 확인하기 (0) | 2022.07.13 |