석그
기억하지말고기록하기
석그
전체 방문자
오늘
어제
  • 분류 전체보기 (75)
    • Docker (2)
    • WEB (10)
      • apache (5)
      • nginx (2)
      • 인증서 (1)
    • WAS (10)
      • wildfly (9)
      • jboss (0)
      • tomcat (0)
    • DevOps (7)
      • Jenkins (2)
      • Influx (2)
      • Ansible (1)
      • gitlab (1)
      • squid (1)
    • ELK (4)
      • elasticsearch (2)
      • Kibana (0)
      • Logstash (2)
    • 리눅스 명령어 (6)
    • GIT (0)
    • 알고리즘 (0)
    • 쉘스크립트 (8)
    • Centos7 (5)
    • TEST (6)
    • Scouter (0)
    • 에러모음 (9)
    • 기타 (4)
      • tool (4)
    • grafana (2)
    • VirtualBox (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 플레이북
  • docker 커밋
  • 문법확인
  • 인증서패스워드
  • apache
  • 싱글인증서
  • ansible
  • 로그크기
  • 쉘패키지
  • cli스크립트
  • Bad GateWay
  • scouter
  • 젠킨스
  • Customizable Alert
  • jkmount
  • 도커이미지저장
  • shellcheck
  • 뒤에서 값자르기
  • 쉘문법
  • 도커 커밋
  • fallocate
  • 변수처리
  • 깃허브
  • 멀티인증서
  • 도커
  • 서버공유
  • 파일변수처리
  • 와일드카드인증서
  • 도커 로드
  • jboss-cli.sh

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
석그

기억하지말고기록하기

[wildfly] Blowfish 암호화/복호화
WAS/wildfly

[wildfly] Blowfish 암호화/복호화

2022. 9. 27. 20:18

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
    'WAS/wildfly' 카테고리의 다른 글
    • 메모리 사용율 확인하기
    • [wildfly] 관리자 페이지 접근 못하게 설정
    • [wildfly] jboss-cli.sh 접속 스크립트
    • [wildfly] 기동이슈
    석그
    석그

    티스토리툴바