Top Description Inners Fields Constructors Methods
java.security

public Class KeyRep

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
javax.crypto.spec.SecretKeySpec, java.io.NotSerializableException, .ObjectStreamException, .Serializable, java.security.spec.PKCS8EncodedKeySpec, .X509EncodedKeySpec, java.util.Locale

Standardized representation for serialized Key objects.

Note that a serialized Key may contain sensitive information which should not be exposed in untrusted environments. See the Security Appendix of the Java Object Serialization Specification for more information.

Since
1.5
See Also
Key, KeyFactory, javax.crypto.spec.SecretKeySpec, java.security.spec.X509EncodedKeySpec, java.security.spec.PKCS8EncodedKeySpec

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
KeyRep.Type

Key type.

Field Summary

Modifier and TypeField and Description
private final String
algorithm

The Key algorithm

private final byte[]
encoded

The encoded Key bytes

private final String
format

The Key encoding format

private static final String
private static final String
private static final long
private final KeyRep.Type
type

Either one of Type.SECRET, Type.PUBLIC, or Type.PRIVATE

private static final String

Constructor Summary

AccessConstructor and Description
public
KeyRep(KeyRep.Type
either one of Type.SECRET, Type.PUBLIC, or Type.PRIVATE
type
,
String
the algorithm returned from Key.getAlgorithm()
algorithm
,
String
the encoding format returned from Key.getFormat()
format
,
byte[]
the encoded bytes returned from Key.getEncoded()
encoded
)

Construct the alternate Key class.

Method Summary

Modifier and TypeMethod and Description
protected Object

Returns:

the resolved Key object
readResolve
()

Resolve the Key object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmback to summary
private final String algorithm

The Key algorithm

encodedback to summary
private final byte[] encoded

The encoded Key bytes

formatback to summary
private final String format

The Key encoding format

PKCS8back to summary
private static final String PKCS8
RAWback to summary
private static final String RAW
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial
typeback to summary
private final KeyRep.Type type

Either one of Type.SECRET, Type.PUBLIC, or Type.PRIVATE

X509back to summary
private static final String X509

Constructor Detail

KeyRepback to summary
public KeyRep(KeyRep.Type type, String algorithm, String format, byte[] encoded)

Construct the alternate Key class.

Parameters
type:KeyRep.Type

either one of Type.SECRET, Type.PUBLIC, or Type.PRIVATE

algorithm:String

the algorithm returned from Key.getAlgorithm()

format:String

the encoding format returned from Key.getFormat()

encoded:byte[]

the encoded bytes returned from Key.getEncoded()

Exceptions
NullPointerException:
if type is null, if algorithm is null, if format is null, or if encoded is null

Method Detail

readResolveback to summary
protected Object readResolve() throws ObjectStreamException

Resolve the Key object.

This method supports three Type/format combinations:

  • Type.SECRET/"RAW" - returns a SecretKeySpec object constructed using encoded key bytes and algorithm
  • Type.PUBLIC/"X.509" - gets a KeyFactory instance for the key algorithm, constructs an X509EncodedKeySpec with the encoded key bytes, and generates a public key from the spec
  • Type.PRIVATE/"PKCS#8" - gets a KeyFactory instance for the key algorithm, constructs a PKCS8EncodedKeySpec with the encoded key bytes, and generates a private key from the spec
Returns:Object

the resolved Key object

Annotations
@Serial
Exceptions
ObjectStreamException:
if the Type/format combination is unrecognized, if the algorithm, key format, or encoded key bytes are unrecognized/invalid, of if the resolution of the key fails for any reason
java.security back to summary

public final Enum KeyRep.Type

extends Enum<KeyRep.Type>
Class Inheritance

Key type.
Since
1.5

Field Summary

Modifier and TypeField and Description
public static final KeyRep.Type
PRIVATE

Type for private keys.

public static final KeyRep.Type
PUBLIC

Type for public keys.

public static final KeyRep.Type
SECRET

Type for secret keys.

Constructor Summary

AccessConstructor and Description
private
Type()

Method Summary

Modifier and TypeMethod and Description
public static KeyRep.Type
public static KeyRep.Type[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

PRIVATEback to summary
public static final KeyRep.Type PRIVATE

Type for private keys.

PUBLICback to summary
public static final KeyRep.Type PUBLIC

Type for public keys.

SECRETback to summary
public static final KeyRep.Type SECRET

Type for secret keys.

Constructor Detail

Typeback to summary
private Type()

Method Detail

valueOfback to summary
public static KeyRep.Type valueOf(String name)
valuesback to summary
public static KeyRep.Type[] values()