Class PublicKey
A public key -- paired with a PrivateKey to form a key pair. Carries the
algorithm name ("RSA" or "EC") and the encoded key bytes.
PEM files (-----BEGIN PUBLIC KEY-----) go through fromPem(String), which
strips the armor and decodes the base64 for you; fromX509(String, byte[]) is the lower
level entry point for callers that already hold the DER bytes.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic PublicKeyfromPem(byte[] pem) fromPem(String)over the raw bytes of a.pemfile, so a stream read withUtil.readInputStreamcan be passed straight in.static PublicKeyParses a PEM-encoded public key, determining the algorithm from the key itself.static PublicKeyfromPem(String,String)over the raw bytes of a.pemfile.static PublicKeyfromPem(String)with the algorithm supplied by the caller rather than read from the key.static PublicKeyWraps an X.509 / SubjectPublicKeyInfo (SPKI) DER blob.static PublicKeyrsa(byte[] x509Der) Convenience: build an RSAPublicKeyfrom afromX509(String, byte[])X.509 blob.Methods inherited from class Key
getAlgorithm, getEncoded, getFormat
-
Field Details
-
RSA
-
EC
-
-
Method Details
-
fromX509
-
rsa
Convenience: build an RSAPublicKeyfrom afromX509(String, byte[])X.509 blob. -
fromPem
Parses a PEM-encoded public key, determining the algorithm from the key itself. This is the form
openssl rsa -puboutand every backend key store hands out:InputStream is = Display.getInstance().getResourceAsStream(MyApp.class, "/public.pem"); PublicKey key = PublicKey.fromPem(Util.readInputStream(is));Accepts a
PUBLIC KEY(SPKI) block, the older PKCS#1RSA PUBLIC KEYblock, and -- for keys carried in JSON or a build hint rather than a file -- bare base64 with no-----BEGIN-----armor at all. Line endings, blank lines and text surrounding the block are ignored, and in a file holding several blocks the first public key is the one used.Throws
CryptoExceptionif the text is not a public key, if it is passphrase-encrypted, or if the key is neither RSA nor EC. -
fromPem
fromPem(String)over the raw bytes of a.pemfile, so a stream read withUtil.readInputStreamcan be passed straight in. The bytes are decoded as UTF-8. -
fromPem
fromPem(String)with the algorithm supplied by the caller rather than read from the key. Use this only for a key whose algorithm OID this class does not recognize but the platform does. -
fromPem
fromPem(String,String)over the raw bytes of a.pemfile.
-