小编Ser*_*ero的帖子

AES加密使用CryptoJS

我需要使用JavaScript实现AES加密.使用AES/CBC/NoPadding模式并创建了一个方法来完成16个长度块.我已经用Java解决了它.看起来像:

public static String encrypt(byte[] key, byte[] initVector, String value) {
    try {
        IvParameterSpec iv = new IvParameterSpec(initVector);
        SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
        Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
        byte[] encrypted = cipher.doFinal(completeBlocks(value));
        return Base64.encodeBase64String(encrypted);
    } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
        System.out.println("Error: " + ex);
    }

    return null;
}

/**
 * Completes 16 lenght blocks
 *
 * @param message
 *
 *
 */
static byte[] completeBlocks(String message) {
    try { …
Run Code Online (Sandbox Code Playgroud)

javascript java encryption aes

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

aes ×1

encryption ×1

java ×1

javascript ×1