package com.example.springboot; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.security.crypto.encrypt.Encryptors; import org.springframework.security.crypto.encrypt.BytesEncryptor; import org.springframework.util.Base64Utils; import org.apache.commons.codec.binary.Hex; @RestController public class HelloController { @RequestMapping("/") public String index() { String plaintext = "ABC"; String encrypted_b64; String encrypted_hex; BytesEncryptor encryptor = Encryptors.stronger("ABCD", "FFFFFFFFFFFFFFFF"); byte[] encrypted = encryptor.encrypt(plaintext.getBytes()); encrypted_b64 = Base64Utils.encodeToString(encrypted); encrypted_hex = Hex.encodeHexString(encrypted); String out="AES\n" + "Plaintext: " + plaintext + "\n" + "Encrypted: " + encrypted_b64 + "\n" + "Encrypted (Hex): " + encrypted_hex + "\n"; System.out.println(out); return out; } }