经过身份验证的加密要求我们使用一些可接受的标准来加密和验证消息。因此,我们都对消息进行加密并在消息上计算MAC以验证它是否未被篡改。
这个问题 概述了一种基于密码的密钥加强和加密的方法:
/* Derive the key, given password and salt. */
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec spec = new PBEKeySpec(password, salt, 65536, 256);
SecretKey tmp = factory.generateSecret(spec);
SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
/* Encrypt the message. */
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secret);
AlgorithmParameters params = cipher.getParameters();
byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV();
byte[] ciphertext = cipher.doFinal("Hello, World!".getBytes("UTF-8"));
但据我所知,这不会计算密文上的任何MAC,因此不安全。在Java中执行经过身份验证的加密的标准是什么?