Package org.bouncycastle.crypto.util
Class JournaledAlgorithm
- java.lang.Object
-
- org.bouncycastle.crypto.util.JournaledAlgorithm
-
- All Implemented Interfaces:
java.io.Serializable
,Encodable
public class JournaledAlgorithm extends java.lang.Object implements Encodable, java.io.Serializable
JournaledAlgorithm keeps state of the JournalingSecureRandom and the AlgorithmIdentifier necessary to fully resume an encryption session. This class can be used to retrieve a session even if a process is completely stopped. NOTE: This should be used with a shutdown hook to save the state of the journaling and the algorithm identifier even in the case of a forced shutdown.The raw encoding is in ASN.1 format.
Details: Use serialization of critical parameters of the the JournalingSecureRandom and AlgorithmIdentifier. Because these two classes are not serializable, create interior class to serialize only the critical parameters in the form of byte[] arrays
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JournaledAlgorithm(byte[] encoding)
Construct from a previous encoding, using CryptoServicesRegistrar.getSecureRandom() as the backup source of entropy.JournaledAlgorithm(byte[] encoding, java.security.SecureRandom random)
Construct from a previous encoding, using the passed in random as a source for when the existing entropy runs out.JournaledAlgorithm(AlgorithmIdentifier aid, JournalingSecureRandom journaling)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AlgorithmIdentifier
getAlgorithmIdentifier()
byte[]
getEncoded()
Return a byte array representing the implementing object.JournalingSecureRandom
getJournalingSecureRandom()
static JournaledAlgorithm
getState(java.io.File tempfile, java.security.SecureRandom random)
Reconstructs JournaledAlgorithm session from file containing it's raw encoding.static JournaledAlgorithm
getState(java.io.InputStream stateIn, java.security.SecureRandom random)
void
storeState(java.io.File tempfile)
Store state of JournalingSecureRandom and AlgorithmIdentifier in temporary filevoid
storeState(java.io.OutputStream out)
-
-
-
Constructor Detail
-
JournaledAlgorithm
public JournaledAlgorithm(AlgorithmIdentifier aid, JournalingSecureRandom journaling)
-
JournaledAlgorithm
public JournaledAlgorithm(byte[] encoding)
Construct from a previous encoding, using CryptoServicesRegistrar.getSecureRandom() as the backup source of entropy.- Parameters:
encoding
- raw encoding of a previous JournaledAlgorithm.
-
JournaledAlgorithm
public JournaledAlgorithm(byte[] encoding, java.security.SecureRandom random)
Construct from a previous encoding, using the passed in random as a source for when the existing entropy runs out.- Parameters:
encoding
- raw encoding of a previous JournaledAlgorithm.random
- back up source of entropy.
-
-
Method Detail
-
getJournalingSecureRandom
public JournalingSecureRandom getJournalingSecureRandom()
-
getAlgorithmIdentifier
public AlgorithmIdentifier getAlgorithmIdentifier()
-
storeState
public void storeState(java.io.File tempfile) throws java.io.IOException
Store state of JournalingSecureRandom and AlgorithmIdentifier in temporary file- Parameters:
tempfile
-- Throws:
java.io.IOException
-
storeState
public void storeState(java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
getState
public static JournaledAlgorithm getState(java.io.InputStream stateIn, java.security.SecureRandom random) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
getState
public static JournaledAlgorithm getState(java.io.File tempfile, java.security.SecureRandom random) throws java.io.IOException, java.lang.ClassNotFoundException
Reconstructs JournaledAlgorithm session from file containing it's raw encoding.- Parameters:
tempfile
- temporary file containing serialized state- Returns:
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
getEncoded
public byte[] getEncoded() throws java.io.IOException
Description copied from interface:Encodable
Return a byte array representing the implementing object.- Specified by:
getEncoded
in interfaceEncodable
- Returns:
- a byte array representing the encoding.
- Throws:
java.io.IOException
- if an issue arises generation the encoding.
-
-