Class KeyGenerator
java.lang.Object
com.codename1.security.KeyGenerator
Generates fresh cryptographic key material. AES keys are pulled directly
from SecureRandom; RSA key pairs are generated by the platform's native
crypto provider.
Example
SecretKey aes = KeyGenerator.aes(256); // AES-256
KeyPair rsa = KeyGenerator.rsa(2048); // RSA-2048
KeyPair ec = KeyGenerator.ec(256); // P-256, for ECDSA and ECDH
-
Method Summary
Modifier and TypeMethodDescriptionstatic SecretKeyaes(int bits) Generates a fresh AES key of the given bit length.static KeyPairec(int bits) Generates a fresh elliptic-curve key pair on NIST P-256 (secp256r1), the curve every platform provider implements.static SecretKeyhmac(int bits) Generates a fresh HMAC key of the given bit length.static KeyPairrsa(int bits) Generates a fresh RSA key pair of the given size in bits.
-
Method Details
-
aes
Generates a fresh AES key of the given bit length. Valid lengths are 128, 192 and 256 bits. -
hmac
Generates a fresh HMAC key of the given bit length. By convention, HMAC keys should be at least as long as the hash output. -
rsa
Generates a fresh RSA key pair of the given size in bits. 2048 is the modern minimum; 3072 / 4096 for higher security margins. Generating a 4096-bit RSA key can take several seconds -- call from a background thread. -
ec
Generates a fresh elliptic-curve key pair on NIST P-256 (secp256r1), the curve every platform provider implements. The pair signs with
Signature.SHA256_WITH_ECDSAand agrees secrets withKeyAgreement.ecdh(PrivateKey, PublicKey).Parameters
bits: the curve size; only 256 is supported
-