Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>public class Crypto { public static String encrypt(String value, String key) throws GeneralSecurityException { SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(key), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, sks, cipher.getParameters()); byte[] encrypted = cipher.doFinal(value.getBytes()); return byteArrayToHexString(encrypted); } public static String decrypt(String message, String key) throws GeneralSecurityException { SecretKeySpec sks = new SecretKeySpec(hexStringToByteArray(key), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, sks); byte[] decrypted = cipher.doFinal(hexStringToByteArray(message)); return new String(decrypted); } private static String byteArrayToHexString(byte[] b){ StringBuffer sb = new StringBuffer(b.length * 2); for (int i = 0; i &lt; b.length; i++){ int v = b[i] &amp; 0xff; if (v &lt; 16) { sb.append('0'); } sb.append(Integer.toHexString(v)); } return sb.toString().toUpperCase(); } private static byte[] hexStringToByteArray(String s) { byte[] b = new byte[s.length() / 2]; for (int i = 0; i &lt; b.length; i++){ int index = i * 2; int v = Integer.parseInt(s.substring(index, index + 2), 16); b[i] = (byte)v; } return b; } } </code></pre> <p>above class will help in encrypt and decrypt string without base64</p> <p>usage of above class </p> <pre><code>try { String key = UUID.randomUUID().toString().replaceAll("-", ""); String src = "Hello world!"; String tag1 = Crypto.encrypt(src, key); String tag2 = Crypto.decrypt(tag1, key); logger.info(src); logger.info(tag1); logger.info(tag2); } catch (Exception e) { logger.error("", e); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload