javax.crypto.spec


1. Generating a SecretKeySpec for AES-256 encryption

import javax.crypto.spec.SecretKeySpec;

byte[] key = "mySecretKey".getBytes("UTF-8");
SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");

2. Generating an IvParameterSpec for CBC mode encryption

import javax.crypto.spec.IvParameterSpec;

byte[] iv = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);

3. Generating a PBEKeySpec for password-based encryption

import javax.crypto.spec.PBEKeySpec;
import java.util.Arrays;

char[] password = "myPassword".toCharArray();
byte[] salt = "mySalt".getBytes("UTF-8");
int iterations = 1000;
PBEKeySpec pbeKeySpec = new PBEKeySpec(password, salt, iterations, 256);

4. Generating a DHParameterSpec for Diffie-Hellman key exchange

5. Generating an EllipticCurveSpec for ECDSA signature verification

6. Generating an OAEPParameterSpec for OAEP padding

7. Generating a PBEParameterSpec for PBE encryption

8. Generating an RSAPrivateKeySpec for RSA decryption

9. Generating an RSAPublicKeySpec for RSA encryption

10. Generating an X509EncodedKeySpec for X.509 certificate decoding

11. Generating a Cipher for AES-256 encryption in CBC mode with PKCS5 padding

12. Generating a Cipher for AES-256 decryption in CBC mode with PKCS5 padding

13. Generating a Cipher for AES-256 encryption in ECB mode with PKCS5 padding

14. Generating a Cipher for AES-256 decryption in ECB mode with PKCS5 padding

15. Generating a Cipher for AES-256 encryption in CFB mode with PKCS5 padding

16. Generating a Cipher for AES-256 decryption in CFB mode with PKCS5 padding

17. Generating a Cipher for AES-256 encryption in OFB mode with PKCS5 padding

18. Generating a Cipher for AES-256 decryption in OFB mode with PKCS5 padding

19. Generating a Cipher for AES-256 encryption in CTR mode

20. Generating a Cipher for AES-256 decryption in CTR mode

21. Generating a Cipher for AES-256 encryption in GCM mode