Java KeyPair
Jakob Jenkov |
The Java KeyPair class (java.security.KeyPair
represents an asymmetric key pair. In other
words, a public key + private key pair. A KeyPair
instance is typically used when performing
asymmetric cryptography, like encrypting or signing data.
Obtaining a KeyPair Instance
You will normally obtain a KeyPair
instance from a Java keystore
or a Java KeyPairGenerator.
Accessing KeyPair Public Key
You can access the PublicKey
of a KeyPair
by calling its getPublic()
method. Her is an example of obtaining the PublicKey
from a KeyPair
instance:
PublicKey publicKey = keyPair.getPublic();
Accessing the KeyPair Private Key
You can access the PrivateKey
of a KeyPair
by calling the getPrivate()
method. Here is an example of obtaining the PrivateKey
from a KeyPair
instance:
PrivateKey privateKey = keyPair.getPrivate();
Tweet | |
Jakob Jenkov |