Nhảy tới nội dung

Đặc tả kỹ thuật

Mã hóa AES

Quy trình mã hóa

  • Bước 1: Sử dụng 16 byte đầu của encryptKey làm IV.
  • Bước 2: Tiến hành mã hóa chuỗi với encryptKey và IV.
  • Bước 3: Trả về chuỗi mã hóa.

Code chi tiết (java):

    public static String encryptAES(String data, String encryptKey) {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
byte[] iv = Arrays.copyOf(Hex.decodeHex(encryptKey), 16);
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
SecretKey priKey = new SecretKeySpec(Hex.decodeHex(encryptKey), "AES");
cipher.init(Cipher.ENCRYPT_MODE, priKey, ivParameterSpec);
byte[] plainText = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(plainText);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

Quy trình giải mã

  • Bước 1: Lấy IV từ 16 byte đầu của Key.
  • Bước 2: Tiến hành giải mã chuỗi với Key và IV.
  • Bước 3: Trả về chuỗi đã giải mã.

Code chi tiết (java):

    public static String decryptAES(String data, String encryptKey) {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
byte[] iv = Arrays.copyOf(Hex.decodeHex(encryptKey), 16);
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
SecretKey priKey = new SecretKeySpec(Hex.decodeHex(encryptKey), "AES");
cipher.init(Cipher.DECRYPT_MODE, priKey, ivParameterSpec);
byte[] plainText = cipher.doFinal(Base64.getDecoder().decode(data));
return new String(plainText);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

Ngân hàng TMCP Kiên Long (KienlongBank)

Hợp tác phát triển bởi Unicloud

Hội sở: 40-42-44 Phạm Hồng Thái, P.Vĩnh Thanh Vân, Tp.Rạch Giá, T.Kiên Giang

Điện thoại: (0297) 3869 950 hoặc (028) 3933 3393

Hotline gọi trong lãnh thổ Việt Nam: 1900 6929

Mã SWIFT: KLBKVNVX

Hotline gọi từ nước ngoài về Việt Nam: (+84) 287309 6929

Email:  kienlong@kienlongbank.com hoặc chamsockhachhang@kienlongbank.com

© 2022 Copyright KienlongBank. All right reserved