- java.lang.Object
-
- org.refcodes.security.alt.chaos.ChaosKey
-
- All Implemented Interfaces:
Serializable
,Key
,SecretKey
,Destroyable
,org.refcodes.mixin.ChildAccessor<ChaosKey>
,org.refcodes.mixin.Disposable
,org.refcodes.mixin.EncodedAccessor
public class ChaosKey extends Object implements SecretKey, org.refcodes.mixin.EncodedAccessor, org.refcodes.mixin.ChildAccessor<ChaosKey>, org.refcodes.mixin.Disposable
The key holding the parameters for the chaos function. Thanks Christian Pontesegger for the very good example on "Writing your own JCA extensions - a full cipher" at: "http://codeandme.blogspot.de/2013/07/writing-your-own-jca-extensions-full.html" and for the very good example on "Writing your own JCA extensions - a simple digest " at: "http://codeandme.blogspot.de/2013/06/writing-your-own-jca-extensions-simple.html"- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.ChildAccessor
org.refcodes.mixin.ChildAccessor.ChildBuilder<T extends Object,B extends org.refcodes.mixin.ChildAccessor.ChildBuilder<T,B>>, org.refcodes.mixin.ChildAccessor.ChildMutator<T extends Object>, org.refcodes.mixin.ChildAccessor.ChildProperty<T extends Object>
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.Disposable
org.refcodes.mixin.Disposable.Disposedable
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.EncodedAccessor
org.refcodes.mixin.EncodedAccessor.EncodedBuilder<B extends org.refcodes.mixin.EncodedAccessor.EncodedBuilder<B>>, org.refcodes.mixin.EncodedAccessor.EncodedMutator, org.refcodes.mixin.EncodedAccessor.EncodedProperty
-
-
Field Summary
Fields Modifier and Type Field Description static int
A_BYTES
The number of bytes required to store Astatic double
A_MAX
The maximum valid A value.static double
A_MIN
The minimum valid A value.static int
ENCODED_LENGTH
The overall encoded length in bytes of theChaosKey
including theChaosOptions
.static String
PROVIDER_NAME
The name of the security provider.static int
S_BYTES
The number of bytes required to store Sstatic long
S_MAX
The maximum valid S value (2^53-1 = MAX_SAFE_INTEGER when floating point is involved).static long
S_MIN
The minimum valid S value (-2^53 = MIN_SAFE_INTEGER when floating point is involved).static long
S_NEGATIVE_MAX
The maximum negative S value (S_NEGATIVE_MAX
xS_POSITIVE_MIN
= 256 possibilities, which is the range of values one byte can represent, which in turn is he atomic data to be encrypted / decrypted).static long
S_POSITIVE_MIN
The minimum positive S value (S_NEGATIVE_MAX
xS_POSITIVE_MIN
= 256 possibilities, which is the range of values one byte can represent, which in turn is he atomic data to be encrypted / decrypted).static int
X_BYTES
The number of bytes required to store Xstatic double
X_MAX
The maximum valid X value.static double
X_MIN
The minimum valid X value.
-
Constructor Summary
Constructors Constructor Description ChaosKey(byte[] aEncoded)
Instantiates theChaosKey
by reversing the result of thegetEncoded()
operation where the byte array contains the values x0, a and s (excluding theChaosOptions
).ChaosKey(byte[] aEncoded, ChaosKey aChildKey)
Instantiates theChaosKey
by reversing the result of thegetEncoded()
operation where the byte array contains the values x0, a and s (including theChaosOptions.getEncoded()
).ChaosKey(char[] aSecret)
Instantiates a newChaosKey
by calculating x0, a and s from the provided char array.ChaosKey(char[] aSecret, ChaosKey aChildKey)
Instantiates a newChaosKey
by calculating x0, a and s from the provided char array.ChaosKey(char[] aSecret, ChaosOptions aChaosOptions)
Instantiates a newChaosKey
by calculating x0, a and s from the provided char array.ChaosKey(char[] aSecret, ChaosOptions aChaosOptions, ChaosKey aChildKey)
Instantiates a newChaosKey
by calculating x0, a and s from the provided char array.ChaosKey(double x0, double a, long s)
Instantiates a newChaosKey
directly from the provided double values.ChaosKey(double x0, double a, long s, ChaosKey aChildKey)
Instantiates a newChaosKey
directly from the provided double values.ChaosKey(double x0, double a, long s, ChaosOptions aChaosOptions)
Instantiates a newChaosKey
directly from the provided double values.ChaosKey(double x0, double a, long s, ChaosOptions aChaosOptions, ChaosKey aChildKey)
Instantiates a newChaosKey
directly from the provided double values.ChaosKey(int x0, int a, int s)
Instantiates a newChaosKey
from the provided integer values.ChaosKey(int x0, int a, int s, ChaosKey aChildKey)
Instantiates a newChaosKey
from the provided integer values.ChaosKey(int x0, int a, int s, ChaosOptions aChaosOptions)
Instantiates a newChaosKey
from the provided integer values.ChaosKey(int x0, int a, int s, ChaosOptions aChaosOptions, ChaosKey aChildKey)
Instantiates a newChaosKey
from the provided integer values.ChaosKey(String aSecret)
ChaosKey(String aSecret, ChaosKey aChildKey)
ChaosKey(String aSecret, ChaosOptions aChaosOptions)
ChaosKey(String aSecret, ChaosOptions aChaosOptions, ChaosKey aChildKey)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static long
addToS(long s, long aAddend)
Adds a value to s so that a result exceedingS_MAX
or {S_MIN
is wrapped around accordingly and any result inbetweenS_POSITIVE_MIN
andS_NEGATIVE_MAX
is moved pastS_POSITIVE_MIN
orS_NEGATIVE_MAX
accordingly.static ChaosOptions
asCertificateOptions(File aCertFile)
Creates aChaosOptions
of the (secured) certificate itself (and not the therein contained key chain) retrieved from the givenFile
.static ChaosOptions
asCertificateOptions(InputStream aInputStream)
Creates aChaosOptions
of the (secured) certificate itself (and not the therein contained key chain) retrieved from the givenInputStream
.static ChaosOptions
asCertificateOptions(String aCertificate)
Creates aChaosOptions
of the (secured) certificate itself (and not the therein contained key chain) retrieved from the givenString
.static ChaosKey
createFromCertificate(File aCertFile)
static ChaosKey
createFromCertificate(File aCertFile, String aPassword)
static ChaosKey
createFromCertificate(InputStream aInputStream)
Creates aChaosKey
(chain) from the unsecured certificate retrieved from the givenInputStream
.static ChaosKey
createFromCertificate(InputStream aInputStream, String aPassword)
Creates aChaosKey
(chain) from the password protected certificate retrieved from the givenInputStream
.static ChaosKey
createFromCertificate(String aCertificate)
Creates aChaosKey
(chain) from the unsecured certificate.static ChaosKey
createFromCertificate(String aCertificate, String aPassword)
Creates aChaosKey
(chain) from the password protected certificate.static ChaosKey
createKeyChain(byte[] aEncodedChain)
Creates aChaosKey
from the provided encoded chain representations (as oftoEncodedChain()
) including all the nestedChaosKey
children.static ChaosKey
createRndKey()
Creates a randomChaosKey
.static ChaosKey
createRndKey(ChaosKey aChildKey)
Creates a randomChaosKey
.static ChaosKey
createRndKey(ChaosOptions aChaosOptions)
Creates a randomChaosKey
.static ChaosKey
createRndKey(ChaosOptions aChaosOptions, ChaosKey aChildKey)
Creates a randomChaosKey
.static ChaosKey
createRndKeyChain(int aChainLength)
Creates a randomChaosKey
chain, where eachChaosKey
references a childChaosKey
(as ofgetChild()
) as defined by the provided chain length and eachChaosKey
in the chain is initialized by its unique random values.static ChaosKey
createRndKeyChain(int aChainLength, ChaosOptions... aChaosOptions)
Creates a randomChaosKey
chain, where eachChaosKey
references a childChaosKey
(as ofgetChild()
) as defined by the provided chain length and eachChaosKey
in the chain is initialized by its unique random values.void
destroy()
void
dispose()
boolean
equals(Object obj)
Returns true if all the passed object is of typeChaosKey
and all the attributes from theChaosKey
are equal to this instance's attributes (as ofgetX0()
,getA()
andgetS()
as well asgetChaosOptions()
andgetChild()
).protected static ChaosOptions
fromCertificateHead(String aCertificateHead)
Extracts aChaosOptions
instance from the provided certificate head.protected static ChaosOptions
fromCertificateTail(String aCertificateTail)
Extracts aChaosOptions
instance from the provided certificate tail.double
getA()
Gets the a.String
getAlgorithm()
ChaosOptions
getChaosOptions()
Returns theChaosOptions
being used to enhance Chaos-based encryption by enabling various additional processing steps.ChaosKey
getChild()
Returns the next outerChaosKey
.byte[]
getEncoded()
Returns the key in its primary encoding format.static int
getEncodedLength()
Returns the length of thisChaosKey
when represented as bytes (as ofgetEncoded()
) (excluding theChaosOptions
).String
getFormat()
long
getS()
Gets the s.double
getX0()
Gets the x0.int
hashCode()
protected static double
toA(int a)
Creates a valid a double from the provided integer (values fromInteger.MIN_VALUE
toInteger.MAX_VALUE
are allowed.protected static double
toA(long a)
Creates a valid a double from the provided long (values fromLong.MIN_VALUE
toLong.MAX_VALUE
are allowed).String
toCertificate()
Creates a certificate for encryption and decryption from thisChaosKey
.String
toCertificate(int aLineWidth)
Creates a certificate for encryption and decryption from thisChaosKey
.String
toCertificate(String aPassword)
Creates a password protected certificate for encryption and decryption from thisChaosKey
.String
toCertificate(String aPassword, int aLineWidth)
Creates a password protected certificate for encryption and decryption from thisChaosKey
.String
toCertificate(String aPassword, ChaosOptions aChaosOptions)
Creates password protected a certificate for encryption and decryption from thisChaosKey
.String
toCertificate(String aPassword, ChaosOptions aChaosOptions, int aLineWidth)
Creates password protected a certificate for encryption and decryption from thisChaosKey
.protected static String
toCertificateHead()
Creates a certificate head for an unsecured certificate.protected static String
toCertificateHead(ChaosOptions aChaosOptions)
Creates a certificate head from the providedChaosOptions
instance for a password protected certificate.protected static String
toCertificateTail()
Creates a certificate tail for an unsecured certificate.protected static String
toCertificateTail(ChaosOptions aChaosOptions)
Creates a certificate tail from the providedChaosOptions
instance for a password protected certificate.byte[]
toEncodedChain()
Returns all encodedChaosKey
representations including thisChaosKey
as well as all the nestedChaosKey
children being their concatenatedgetEncoded()
representation, the this being first and the bottom most child the last.protected static long
toS(int s)
Creates a valid s double from the provided integer (values fromInteger.MIN_VALUE
toInteger.MAX_VALUE
are allowed).protected static long
toS(long s)
Creates a valid s long from the provided long (values fromLong.MIN_VALUE
toLong.MAX_VALUE
are allowed).String
toString()
protected static double
toX0(int x0)
Creates a valid x0 double from the provided integer (values fromInteger.MIN_VALUE
toInteger.MAX_VALUE
are allowed.protected static double
toX0(long x0)
Creates a valid x0 double from the provided long (values fromLong.MIN_VALUE
toLong.MAX_VALUE
are allowed).protected static void
validate(double x0, double a, double s)
Validates the given values whether them are in scope.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.security.auth.Destroyable
isDestroyed
-
-
-
-
Field Detail
-
PROVIDER_NAME
public static final String PROVIDER_NAME
The name of the security provider.- See Also:
- Constant Field Values
-
A_BYTES
public static final int A_BYTES
The number of bytes required to store A- See Also:
- Constant Field Values
-
A_MAX
public static final double A_MAX
The maximum valid A value.- See Also:
- Constant Field Values
-
A_MIN
public static final double A_MIN
The minimum valid A value.- See Also:
- Constant Field Values
-
S_BYTES
public static final int S_BYTES
The number of bytes required to store S- See Also:
- Constant Field Values
-
S_MAX
public static final long S_MAX
The maximum valid S value (2^53-1 = MAX_SAFE_INTEGER when floating point is involved).- See Also:
- Constant Field Values
-
S_MIN
public static final long S_MIN
The minimum valid S value (-2^53 = MIN_SAFE_INTEGER when floating point is involved).- See Also:
- Constant Field Values
-
S_NEGATIVE_MAX
public static final long S_NEGATIVE_MAX
The maximum negative S value (S_NEGATIVE_MAX
xS_POSITIVE_MIN
= 256 possibilities, which is the range of values one byte can represent, which in turn is he atomic data to be encrypted / decrypted).- See Also:
- Constant Field Values
-
S_POSITIVE_MIN
public static final long S_POSITIVE_MIN
The minimum positive S value (S_NEGATIVE_MAX
xS_POSITIVE_MIN
= 256 possibilities, which is the range of values one byte can represent, which in turn is he atomic data to be encrypted / decrypted).- See Also:
- Constant Field Values
-
X_BYTES
public static final int X_BYTES
The number of bytes required to store X- See Also:
- Constant Field Values
-
X_MAX
public static final double X_MAX
The maximum valid X value.- See Also:
- Constant Field Values
-
X_MIN
public static final double X_MIN
The minimum valid X value.- See Also:
- Constant Field Values
-
ENCODED_LENGTH
public static final int ENCODED_LENGTH
The overall encoded length in bytes of theChaosKey
including theChaosOptions
.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ChaosKey
public ChaosKey(byte[] aEncoded)
Instantiates theChaosKey
by reversing the result of thegetEncoded()
operation where the byte array contains the values x0, a and s (excluding theChaosOptions
). The values use a big endian representation. The byte array being passed is to be of the size as returned bygetEncodedLength()
. The number of bytes required by each value in the byte array are defined in the constants 8,A_BYTES
andS_BYTES
respectively and in that order.- Parameters:
aEncoded
- The encoded representation of the chaos key.
-
ChaosKey
public ChaosKey(double x0, double a, long s)
Instantiates a newChaosKey
directly from the provided double values. Make sure your provided arguments are within the allowed bounds;- Parameters:
x0
- the x0: (0 <= x0 <= 1 )a
- the a: (a <= 3.57 <= 4 )s
- the s: (Integer.MAX_VALUE
>= s >=Integer.MAX_VALUE
AND 16 <= s <= -16)
-
ChaosKey
public ChaosKey(double x0, double a, long s, ChaosOptions aChaosOptions)
Instantiates a newChaosKey
directly from the provided double values. Make sure your provided arguments are within the allowed bounds;- Parameters:
x0
- the x0: (0 <= x0 <= 1 )a
- the a: (a <= 3.57 <= 4 )s
- the s: (Integer.MAX_VALUE
>= s >=Integer.MAX_VALUE
AND 16 <= s <= -16)aChaosOptions
- TheChaosMode
(ChaosOptions
) to use to enhance Chaos-based encryption by enabling various additional processing steps.
-
ChaosKey
public ChaosKey(int x0, int a, int s)
Instantiates a newChaosKey
from the provided integer values. The integers are converted to the valid ranges of double values for invoking the constructorChaosKey(double, double, long)
. You can use values in the range ofInteger.MIN_VALUE
andInteger.MAX_VALUE
.- Parameters:
x0
- The value from which to calculate the valid x0 double.a
- The value from which to calculate the valid a double.s
- The value from which to calculate the valid s double.
-
ChaosKey
public ChaosKey(int x0, int a, int s, ChaosOptions aChaosOptions)
Instantiates a newChaosKey
from the provided integer values. The integers are converted to the valid ranges of double values for invoking the constructorChaosKey(double, double, long)
. You can use values in the range ofInteger.MIN_VALUE
andInteger.MAX_VALUE
.- Parameters:
x0
- The value from which to calculate the valid x0 double.a
- The value from which to calculate the valid a double.s
- The value from which to calculate the valid s double.aChaosOptions
- TheChaosMode
(ChaosOptions
) to use to enhance Chaos-based encryption by enabling various additional processing steps.
-
ChaosKey
public ChaosKey(char[] aSecret)
Instantiates a newChaosKey
by calculating x0, a and s from the provided char array.- Parameters:
aSecret
- The char array (in contrast to aString
, a char array can be invalidated after use by overwriting its array elements with random values) from which to calculate x0, a and s.
-
ChaosKey
public ChaosKey(String aSecret)
- Parameters:
aSecret
- TheString
from which to calculate x0, a and s.
-
ChaosKey
public ChaosKey(char[] aSecret, ChaosOptions aChaosOptions)
Instantiates a newChaosKey
by calculating x0, a and s from the provided char array.- Parameters:
aSecret
- The char array (in contrast to aString
, a char array can be invalidated after use by overwriting its array elements with random values) from which to calculate x0, a and s.aChaosOptions
- TheChaosMode
(ChaosOptions
) to use to enhance Chaos-based encryption.
-
ChaosKey
public ChaosKey(String aSecret, ChaosOptions aChaosOptions)
- Parameters:
aSecret
- TheString
from which to calculate x0, a and s.aChaosOptions
- TheChaosMode
(ChaosOptions
) to use to enhance Chaos-based encryption.
-
ChaosKey
public ChaosKey(double x0, double a, long s, ChaosKey aChildKey)
Instantiates a newChaosKey
directly from the provided double values. Make sure your provided arguments are within the allowed bounds;- Parameters:
x0
- the x0: (0 <= x0 <= 1 )a
- the a: (a <= 3.57 <= 4 )s
- the s: (Integer.MAX_VALUE
>= s >=Integer.MAX_VALUE
AND 16 <= s <= -16)aChildKey
- The childChaosKey
being the successor of thisChaosKey
to encrypt and the predecessor of thisChaosKey
to decrypt.
-
ChaosKey
public ChaosKey(int x0, int a, int s, ChaosKey aChildKey)
Instantiates a newChaosKey
from the provided integer values. The integers are converted to the valid ranges of double values for invoking the constructorChaosKey(double, double, long)
. You can use values in the range ofInteger.MIN_VALUE
andInteger.MAX_VALUE
.- Parameters:
x0
- The value from which to calculate the valid x0 double.a
- The value from which to calculate the valid a double.s
- The value from which to calculate the valid s double.aChildKey
- The childChaosKey
being the successor of thisChaosKey
to encrypt and the predecessor of thisChaosKey
to decrypt.
-
ChaosKey
public ChaosKey(int x0, int a, int s, ChaosOptions aChaosOptions, ChaosKey aChildKey)
Instantiates a newChaosKey
from the provided integer values. The integers are converted to the valid ranges of double values for invoking the constructorChaosKey(double, double, long)
. You can use values in the range ofInteger.MIN_VALUE
andInteger.MAX_VALUE
.- Parameters:
x0
- The value from which to calculate the valid x0 double.a
- The value from which to calculate the valid a double.s
- The value from which to calculate the valid s double.aChaosOptions
- TheChaosMode
(ChaosOptions
) to use to enhance Chaos-based encryption by enabling various additional processing steps.aChildKey
- The childChaosKey
being the successor of thisChaosKey
to encrypt and the predecessor of thisChaosKey
to decrypt.
-
ChaosKey
public ChaosKey(char[] aSecret, ChaosKey aChildKey)
Instantiates a newChaosKey
by calculating x0, a and s from the provided char array.- Parameters:
aSecret
- The char array (in contrast to aString
, a char array can be invalidated after use by overwriting its array elements with random values) from which to calculate x0, a and s.aChildKey
- The childChaosKey
being the successor of thisChaosKey
to encrypt and the predecessor of thisChaosKey
to decrypt.
-
ChaosKey
public ChaosKey(byte[] aEncoded, ChaosKey aChildKey)
Instantiates theChaosKey
by reversing the result of thegetEncoded()
operation where the byte array contains the values x0, a and s (including theChaosOptions.getEncoded()
). The values use a big endian representation. The byte array being passed is to be of the size as returned bygetEncodedLength()
. The number of bytes required by each value in the byte array are defined in the constants 8,A_BYTES
andS_BYTES
respectively and in that order.
-
ChaosKey
public ChaosKey(double x0, double a, long s, ChaosOptions aChaosOptions, ChaosKey aChildKey)
Instantiates a newChaosKey
directly from the provided double values. Make sure your provided arguments are within the allowed bounds;- Parameters:
x0
- the x0: (0 <= x0 <= 1 )a
- the a: (a <= 3.57 <= 4 )s
- the s: (Integer.MAX_VALUE
>= s >=Integer.MAX_VALUE
AND 16 <= s <= -16)aChaosOptions
- TheChaosMode
(ChaosOptions
) to use to enhance Chaos-based encryption by enabling various additional processing steps.aChildKey
- The childChaosKey
being the successor of thisChaosKey
to encrypt and the predecessor of thisChaosKey
to decrypt.
-
ChaosKey
public ChaosKey(char[] aSecret, ChaosOptions aChaosOptions, ChaosKey aChildKey)
Instantiates a newChaosKey
by calculating x0, a and s from the provided char array.- Parameters:
aSecret
- The char array (in contrast to aString
, a char array can be invalidated after use by overwriting its array elements with random values) from which to calculate x0, a and s.aChaosOptions
- TheChaosMode
(ChaosOptions
) to use to enhance Chaos-based encryption.aChildKey
- The childChaosKey
being the successor of thisChaosKey
to encrypt and the predecessor of thisChaosKey
to decrypt.
-
ChaosKey
public ChaosKey(String aSecret, ChaosOptions aChaosOptions, ChaosKey aChildKey)
-
-
Method Detail
-
destroy
public void destroy() throws DestroyFailedException
- Specified by:
destroy
in interfaceDestroyable
- Throws:
DestroyFailedException
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceorg.refcodes.mixin.Disposable
-
getA
public double getA()
Gets the a.- Returns:
- the a
-
getAlgorithm
public String getAlgorithm()
- Specified by:
getAlgorithm
in interfaceKey
-
getChaosOptions
public ChaosOptions getChaosOptions()
Returns theChaosOptions
being used to enhance Chaos-based encryption by enabling various additional processing steps. Defaults toChaosMode.NONE
.- Returns:
- the chaos metrics
-
getEncoded
public byte[] getEncoded()
Returns the key in its primary encoding format. Returns the bytes in a defined order representing the x0, a and s values (including theChaosOptions.getEncoded()
). The values use a big endian representation. The byte array being returned is of the size as returned bygetEncodedLength()
. The number of bytes required by each value in the byte array are defined in the constants 8,A_BYTES
andS_BYTES
respectively and in that order.- Specified by:
getEncoded
in interfaceorg.refcodes.mixin.EncodedAccessor
- Specified by:
getEncoded
in interfaceKey
- Returns:
- The encoded key being the according bytes representing the
ChaosKey
x0, a and s values.
-
toEncodedChain
public byte[] toEncodedChain()
Returns all encodedChaosKey
representations including thisChaosKey
as well as all the nestedChaosKey
children being their concatenatedgetEncoded()
representation, the this being first and the bottom most child the last. Invoking thecreateKeyChain(byte[])
method with the result of this method reconstructs theChaosKey
chain's instances.- Returns:
- The bytes representation of this
ChaosKey
and its nestedChaosKey
children as of theirgetEncoded()
representation.
-
getChild
public ChaosKey getChild()
-
getS
public long getS()
Gets the s.- Returns:
- the s
-
getX0
public double getX0()
Gets the x0.- Returns:
- the x0
-
toCertificate
public String toCertificate()
Creates a certificate for encryption and decryption from thisChaosKey
. The certificate is not password protected!
-
toCertificate
public String toCertificate(int aLineWidth)
Creates a certificate for encryption and decryption from thisChaosKey
. The certificate is not password protected!
-
toCertificate
public String toCertificate(String aPassword)
Creates a password protected certificate for encryption and decryption from thisChaosKey
.
-
toCertificate
public String toCertificate(String aPassword, int aLineWidth)
Creates a password protected certificate for encryption and decryption from thisChaosKey
.
-
toCertificate
public String toCertificate(String aPassword, ChaosOptions aChaosOptions)
Creates password protected a certificate for encryption and decryption from thisChaosKey
.- Parameters:
aPassword
- The password with which to protect the key.aChaosOptions
- TheChaosOptions
to use for the certificate encryption.- Returns:
- The
String
certificate representation of thisChaosKey
.
-
toCertificate
public String toCertificate(String aPassword, ChaosOptions aChaosOptions, int aLineWidth)
Creates password protected a certificate for encryption and decryption from thisChaosKey
.- Parameters:
aPassword
- The password with which to protect the key.aChaosOptions
- TheChaosOptions
to use for the certificate encryption.aLineWidth
- The line width to use for the encoded certificate data (excluding the head and the tail).- Returns:
- The
String
certificate representation of thisChaosKey
.
-
equals
public boolean equals(Object obj)
Returns true if all the passed object is of typeChaosKey
and all the attributes from theChaosKey
are equal to this instance's attributes (as ofgetX0()
,getA()
andgetS()
as well asgetChaosOptions()
andgetChild()
).
-
createFromCertificate
public static ChaosKey createFromCertificate(File aCertFile, String aPassword) throws IOException
- Parameters:
aCertFile
- TheFile
pointing to the certificate representing theChaosKey
.aPassword
- The password protecting the certificate.- Returns:
- The
ChaosKey
(chain) represented by the certificate. - Throws:
IOException
- thrown in case an I/O related problem occurred while accessing theFile
.
-
createFromCertificate
public static ChaosKey createFromCertificate(InputStream aInputStream, String aPassword) throws IOException
Creates aChaosKey
(chain) from the password protected certificate retrieved from the givenInputStream
.- Parameters:
aInputStream
- TheInputStream
providing the certificate representing theChaosKey
.aPassword
- The password protecting the certificate.- Returns:
- The
ChaosKey
(chain) represented by the certificate. - Throws:
IOException
- thrown in case an I/O related problem occurred while accessing theInputStream
.
-
createFromCertificate
public static ChaosKey createFromCertificate(String aCertificate, String aPassword)
Creates aChaosKey
(chain) from the password protected certificate.
-
createFromCertificate
public static ChaosKey createFromCertificate(File aCertFile) throws IOException
- Parameters:
aCertFile
- TheFile
pointing to the certificate representing theChaosKey
.- Returns:
- The
ChaosKey
(chain) represented by the certificate. - Throws:
IOException
- thrown in case an I/O related problem occurred while accessing theFile
.
-
createFromCertificate
public static ChaosKey createFromCertificate(InputStream aInputStream) throws IOException
Creates aChaosKey
(chain) from the unsecured certificate retrieved from the givenInputStream
.- Parameters:
aInputStream
- TheInputStream
providing the certificate representing theChaosKey
.- Returns:
- The
ChaosKey
(chain) represented by the certificate. - Throws:
IOException
- thrown in case an I/O related problem occurred while accessing theInputStream
.
-
createFromCertificate
public static ChaosKey createFromCertificate(String aCertificate)
Creates aChaosKey
(chain) from the unsecured certificate.
-
createKeyChain
public static ChaosKey createKeyChain(byte[] aEncodedChain)
Creates aChaosKey
from the provided encoded chain representations (as oftoEncodedChain()
) including all the nestedChaosKey
children.- Parameters:
aEncodedChain
- The byte array representing theChaosKey
chain's encoding (as oftoEncodedChain()
).- Returns:
- The reconstructed
ChaosKey
chain from the provided encoded chain representation.
-
createRndKeyChain
public static ChaosKey createRndKeyChain(int aChainLength)
Creates a randomChaosKey
chain, where eachChaosKey
references a childChaosKey
(as ofgetChild()
) as defined by the provided chain length and eachChaosKey
in the chain is initialized by its unique random values.- Parameters:
aChainLength
- The number ofChaosKey
instances chained behind each other as ofgetChild()
- Returns:
- the
ChaosKey
with the according chain length being initialized with random values.
-
createRndKeyChain
public static ChaosKey createRndKeyChain(int aChainLength, ChaosOptions... aChaosOptions)
Creates a randomChaosKey
chain, where eachChaosKey
references a childChaosKey
(as ofgetChild()
) as defined by the provided chain length and eachChaosKey
in the chain is initialized by its unique random values.- Parameters:
aChainLength
- The number ofChaosKey
instances chained behind each other as ofgetChild()
aChaosOptions
- TheChaosOptions
to use for eachChaosKey
, the first one is used for the top most parentChaosKey
, the others for the succeedingChaosKey
children. The lastChaosOptions
element is used for anyChaosKey
to be created exceeding the length of theChaosOptions
elements.- Returns:
- the
ChaosKey
with the according chain length being initialized with random values.
-
createRndKey
public static ChaosKey createRndKey()
Creates a randomChaosKey
. UsegetX0()
,getA()
andgetS()
orgetEncoded()
to retrieve the parameters of the createdChaosKey
.- Returns:
- the
ChaosKey
being initialized with random values.
-
createRndKey
public static ChaosKey createRndKey(ChaosOptions aChaosOptions)
Creates a randomChaosKey
. UsegetX0()
,getA()
andgetS()
orgetEncoded()
to retrieve the parameters of the createdChaosKey
.- Parameters:
aChaosOptions
- TheChaosMode
(ChaosOptions
) to use to enhance Chaos-based encryption.- Returns:
- the
ChaosKey
being initialized with random values.
-
createRndKey
public static ChaosKey createRndKey(ChaosOptions aChaosOptions, ChaosKey aChildKey)
-
asCertificateOptions
public static ChaosOptions asCertificateOptions(File aCertFile) throws IOException, IllegalArgumentException
Creates aChaosOptions
of the (secured) certificate itself (and not the therein contained key chain) retrieved from the givenFile
.- Parameters:
aCertFile
- TheFile
pointing to the certificate representing which'sChaosOptions
are to be determined.- Returns:
- The
ChaosOptions
of the certificate itself or null if it is an unsecured certificate. - Throws:
IOException
- thrown in case an I/O related problem occurred while accessing theFile
.IllegalArgumentException
- thrown in case the provided certificate does not match aChaosKey
certificate notation.
-
asCertificateOptions
public static ChaosOptions asCertificateOptions(InputStream aInputStream) throws IOException, IllegalArgumentException
Creates aChaosOptions
of the (secured) certificate itself (and not the therein contained key chain) retrieved from the givenInputStream
.- Parameters:
aInputStream
- TheInputStream
pointing to the certificate representing which'sChaosOptions
are to be determined.- Returns:
- The
ChaosOptions
of the certificate itself or null if it is an unsecured certificate - Throws:
IOException
- thrown in case an I/O related problem occurred while accessing theInputStream
.IllegalArgumentException
- thrown in case the provided certificate does not match aChaosKey
certificate notation.
-
asCertificateOptions
public static ChaosOptions asCertificateOptions(String aCertificate) throws IllegalArgumentException
Creates aChaosOptions
of the (secured) certificate itself (and not the therein contained key chain) retrieved from the givenString
.- Parameters:
aCertificate
- TheString
representing the certificatewhich'sChaosOptions
are to be determined.- Returns:
- The
ChaosOptions
of the certificate itself or null if it is an unsecured certificate - Throws:
IllegalArgumentException
- thrown in case the provided certificate does not match aChaosKey
certificate notation.
-
getEncodedLength
public static int getEncodedLength()
Returns the length of thisChaosKey
when represented as bytes (as ofgetEncoded()
) (excluding theChaosOptions
).- Returns:
- The number of bytes required to represent a
ChaosKey
x0, a and s values.
-
addToS
protected static long addToS(long s, long aAddend)
Adds a value to s so that a result exceedingS_MAX
or {S_MIN
is wrapped around accordingly and any result inbetweenS_POSITIVE_MIN
andS_NEGATIVE_MAX
is moved pastS_POSITIVE_MIN
orS_NEGATIVE_MAX
accordingly.- Parameters:
s
- The value to which to add an summand.aAddend
- The summand to be added to s.- Returns:
- The accordingly wrapped new s value.
-
toA
protected static double toA(int a)
Creates a valid a double from the provided integer (values fromInteger.MIN_VALUE
toInteger.MAX_VALUE
are allowed.- Parameters:
a
- The integer as source for a- Returns:
- The a inside the valid scope.
-
toA
protected static double toA(long a)
Creates a valid a double from the provided long (values fromLong.MIN_VALUE
toLong.MAX_VALUE
are allowed).- Parameters:
a
- The long as source for a- Returns:
- The a inside the valid scope.
-
toS
protected static long toS(int s)
Creates a valid s double from the provided integer (values fromInteger.MIN_VALUE
toInteger.MAX_VALUE
are allowed).- Parameters:
s
- The integer as source for s- Returns:
- The s inside the valid scope.
-
toS
protected static long toS(long s)
Creates a valid s long from the provided long (values fromLong.MIN_VALUE
toLong.MAX_VALUE
are allowed).- Parameters:
s
- The long as source for s- Returns:
- The s inside the valid scope.
-
toX0
protected static double toX0(int x0)
Creates a valid x0 double from the provided integer (values fromInteger.MIN_VALUE
toInteger.MAX_VALUE
are allowed.- Parameters:
x0
- The integer as source for x0- Returns:
- The x0 inside the valid scope.
-
toX0
protected static double toX0(long x0)
Creates a valid x0 double from the provided long (values fromLong.MIN_VALUE
toLong.MAX_VALUE
are allowed).- Parameters:
x0
- The long as source for x0- Returns:
- The x0 inside the valid scope.
-
validate
protected static void validate(double x0, double a, double s)
Validates the given values whether them are in scope.- Parameters:
x0
- The x0 value to validate.a
- The a value to validate.s
- The s value to validate.
-
fromCertificateHead
protected static ChaosOptions fromCertificateHead(String aCertificateHead) throws IllegalArgumentException
Extracts aChaosOptions
instance from the provided certificate head.- Parameters:
aCertificateHead
- The head (first line) of the certificate in question.- Returns:
- The according
ChaosOptions
instance. - Throws:
IllegalArgumentException
- in case the certificate head is not valid for creating aChaosOptions
instance.
-
fromCertificateTail
protected static ChaosOptions fromCertificateTail(String aCertificateTail) throws IllegalArgumentException
Extracts aChaosOptions
instance from the provided certificate tail.- Parameters:
aCertificateTail
- The tail (last line) of the certificate in question.- Returns:
- The according
ChaosOptions
instance. - Throws:
IllegalArgumentException
- in case the certificate tail is not valid for creating aChaosOptions
instance.
-
toCertificateHead
protected static String toCertificateHead()
Creates a certificate head for an unsecured certificate.- Returns:
- The accordingly created certificate head.
-
toCertificateHead
protected static String toCertificateHead(ChaosOptions aChaosOptions)
Creates a certificate head from the providedChaosOptions
instance for a password protected certificate.- Parameters:
aChaosOptions
- TheChaosOptions
from which to create the certificate head.- Returns:
- The accordingly created certificate head.
-
toCertificateTail
protected static String toCertificateTail()
Creates a certificate tail for an unsecured certificate.- Returns:
- The accordingly created certificate tail.
-
toCertificateTail
protected static String toCertificateTail(ChaosOptions aChaosOptions)
Creates a certificate tail from the providedChaosOptions
instance for a password protected certificate.- Parameters:
aChaosOptions
- TheChaosOptions
from which to create the certificate tail.- Returns:
- The accordingly created certificate tail.
-
-