public class CryptoKeyFactory
extends java.lang.Object
Key
s.Constructor and Description |
---|
CryptoKeyFactory() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
exportKey(java.security.Key key)
Serialises a key into a string using Base64 encoding.
|
static void |
exportKey(java.security.Key key,
java.io.OutputStream out)
Serialises a key into a given stream using Base64 encoding.
|
static java.lang.String |
exportNewKey(CryptoAlgoSpec algo)
Generates a new key and serialises it using Base64 encoding.
|
static java.security.Key |
generateKey(CryptoAlgoSpec algo)
Generates a security
Key for the given algorithm. |
static java.security.Key |
importKey(java.io.InputStream in)
De-serialises a key from a given Base64-encoded stream.
|
static java.security.Key |
importKey(java.lang.String encodedKey)
De-serialises a key from a given Base64-encoded string.
|
public static java.security.Key generateKey(CryptoAlgoSpec algo)
Key
for the given algorithm.algo
- the algorithm to use.java.lang.NullPointerException
- if the argument is null
.public static void exportKey(java.security.Key key, java.io.OutputStream out)
key
- the key to serialise.out
- the destination stream to write the data to.java.lang.NullPointerException
- if any argument is null
.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException
):
IOException
if an error occurs while writing to the stream.
importKey(InputStream)
public static java.lang.String exportKey(java.security.Key key)
exportKey
,
capturing the output in a string.key
- the key to serialise.java.lang.NullPointerException
- if the argument is null
.public static java.security.Key importKey(java.io.InputStream in)
in
- contains the key object as serialised by the export
method.java.lang.NullPointerException
- if the argument is null
.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException
):
IOException
if an error occurs while reading from the stream.
ClassNotFoundException
if an error occurs while instantiating
the key object.
exportKey(Key, OutputStream)
public static java.security.Key importKey(java.lang.String encodedKey)
encodedKey
- contains the key object as serialised by the export
method.java.lang.NullPointerException
- if the argument is null
.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException
):
IOException
if an error occurs while reading from the string.
ClassNotFoundException
if an error occurs while instantiating
the key object.
exportKey(Key, OutputStream)
,
exportNewKey(CryptoAlgoSpec)
public static java.lang.String exportNewKey(CryptoAlgoSpec algo)
generateKey
and exportKey
, capturing the
output in a string.algo
- the algorithm to use.java.lang.NullPointerException
- if the argument is null
.