mysql aes与java aes实现相同密码相同结果的代码

来源:互联网 发布:推荐好看的漫画书 知乎 编辑:程序博客网 时间:2024/06/05 09:04
SELECT HEX(aes_encrypt("password", "0123456789012345"));

Java function:

public static String aes_encrypt(String password, String strKey) {    try {        byte[] keyBytes = Arrays.copyOf(strKey.getBytes("ASCII"), 16);        SecretKey key = new SecretKeySpec(keyBytes, "AES");        Cipher cipher = Cipher.getInstance("AES");        cipher.init(Cipher.ENCRYPT_MODE, key);        byte[] cleartext = password.getBytes("UTF-8");        byte[] ciphertextBytes = cipher.doFinal(cleartext);        return new String(Hex.encodeHex(ciphertextBytes));    } catch (UnsupportedEncodingException e) {        e.printStackTrace();    } catch (NoSuchAlgorithmException e) {        e.printStackTrace();    } catch (NoSuchPaddingException e) {        e.printStackTrace();    } catch (InvalidKeyException e) {        e.printStackTrace();    } catch (IllegalBlockSizeException e) {        e.printStackTrace();    } catch (BadPaddingException e) {        e.printStackTrace();    } return null;}
原创粉丝点击