EC signature algorithm | Requires EC JWK with curve |
---|---|
ES256 | P-256 |
ES384 | P-384 |
ES512 | P-521 |
HMAC algorithm | Required key size |
---|---|
HS256 | 256 bits |
HS384 | 384 bits |
HS512 | 512 bits |
java.security
package. That’s mean we have to import this package into our code. The class for generating the key pairs is KeyPairGenerator
. To get an instance of this class we have to call the getInstance()
methods by providing two parameters. The first parameter is algorithm and the second parameter is the provider.initialize()
method takes two parameters, the key size and a source of randomness. We set the key size to 1024
and pass and instance of SecureRandom
.generateKeyPair()
method of the KeyPairGenerator
class. This will return a KeyPair
object from where we can get the PrivateKey
and PublicKey
by calling the getPrivate()
and getPublic()
method.