Aes256 암호화 방식

탈 SI 개발자로 성장하기/IT 상식 2022.03.21 댓글 gallo44
반응형
Public static aesEncrypt (final String encryptKey, fianl String enData) {
    
    byte [] key = encryptKey.getByte("UTF-8");
    byte [] iv = key.substring(0,16).getByte("UTF-8");

    SecretKey secretKey = new SecretKeySpec(keyData, "AES");
    Cipher cipher = Cipher.getInstance("AES//CBC/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(iv));

    byte [] encrpted = cipher.doFinal(enData.getByte("UTF-8"));
    
    String result = new String (Base64.getEncoder().encode(encrpted));

    return result;
}

 

회사에서 필요한 곳이 있어서 이번에 처음 만들었는데 생각보다 잘 되서 써본다.

나중에 관련 내용을 정리해서 암복호화의 기본 개념과  aes256 방식 암호화, 암복호화 코딩 내용 등을 올려보도록 한다.

집에서는 키보드가 영 구려서 개발이 안된다. 갖다 버리든가 해야지.

반응형

댓글