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:
-
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.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
Modifier and TypeFieldDescriptionstatic final int
The number of bytes required to store Astatic final double
The maximum valid A value.static final double
The minimum valid A value.static final int
The overall encoded length in bytes of theChaosKey
including theChaosOptions
.static final String
The name of the security provider.static final int
The number of bytes required to store Sstatic final long
The maximum valid S value (2^53-1 = MAX_SAFE_INTEGER when floating point is involved).static final long
The minimum valid S value (-2^53 = MIN_SAFE_INTEGER when floating point is involved).static final long
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 final long
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 final int
The number of bytes required to store Xstatic final double
The maximum valid X value.static final double
The minimum valid X value. -
Constructor Summary
ConstructorDescriptionChaosKey
(byte[] aEncoded) Instantiates theChaosKey
by reversing the result of thegetEncoded()
operation where the byte array contains the values x0, a and s (excluding theChaosOptions
).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.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.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.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, ChaosOptions aChaosOptions) ChaosKey
(String aSecret, ChaosOptions aChaosOptions, ChaosKey aChildKey) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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
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
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 asgetOptions()
andgetChild()
).protected int
Determines the number ofChaosKey
children in a row which when applied produce output of the same length as the input was.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.getChild()
Returns the next outerChaosKey
.byte[]
Returns the key in its primary encoding format.static int
Returns the length of thisChaosKey
when represented as bytes (as ofgetEncoded()
) (excluding theChaosOptions
).Returns theChaosOptions
being used to enhance Chaos-based encryption by enabling various additional processing steps.long
getS()
Gets the s.double
getX0()
Gets the x0.int
hashCode()
protected ChaosKey
Determines the nextChaosKey
child (excluding this) which does not(!)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).Creates a certificate for encryption and decryption from thisChaosKey
.toCertificate
(int aLineWidth) Creates a certificate for encryption and decryption from thisChaosKey
.toCertificate
(String aPassword) Creates a password protected certificate for encryption and decryption from thisChaosKey
.toCertificate
(String aPassword, int aLineWidth) Creates a password protected certificate for encryption and decryption from thisChaosKey
.toCertificate
(String aPassword, ChaosOptions aChaosOptions) Creates password protected a certificate for encryption and decryption from thisChaosKey
.toCertificate
(String aPassword, ChaosOptions aChaosOptions, int aLineWidth) Creates password protected a certificate for encryption and decryption from thisChaosKey
.protected static String
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
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[]
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).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 Details
-
PROVIDER_NAME
The name of the security provider.- See Also:
-
A_BYTES
public static final int A_BYTESThe number of bytes required to store A- See Also:
-
A_MAX
public static final double A_MAXThe maximum valid A value.- See Also:
-
A_MIN
public static final double A_MINThe minimum valid A value.- See Also:
-
S_BYTES
public static final int S_BYTESThe number of bytes required to store S- See Also:
-
S_MAX
public static final long S_MAXThe maximum valid S value (2^53-1 = MAX_SAFE_INTEGER when floating point is involved).- See Also:
-
S_MIN
public static final long S_MINThe minimum valid S value (-2^53 = MIN_SAFE_INTEGER when floating point is involved).- See Also:
-
S_NEGATIVE_MAX
public static final long S_NEGATIVE_MAXThe 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:
-
S_POSITIVE_MIN
public static final long S_POSITIVE_MINThe 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:
-
X_BYTES
public static final int X_BYTESThe number of bytes required to store X- See Also:
-
X_MAX
public static final double X_MAXThe maximum valid X value.- See Also:
-
X_MIN
public static final double X_MINThe minimum valid X value.- See Also:
-
ENCODED_LENGTH
public static final int ENCODED_LENGTHThe overall encoded length in bytes of theChaosKey
including theChaosOptions
.- See Also:
-
-
Constructor Details
-
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
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
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
- Parameters:
aSecret
- TheString
from which to calculate x0, a and s.
-
ChaosKey
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
- Parameters:
aSecret
- TheString
from which to calculate x0, a and s.aChaosOptions
- TheChaosMode
(ChaosOptions
) to use to enhance Chaos-based encryption.
-
ChaosKey
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
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
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
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
-
ChaosKey
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
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
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
-
-
Method Details
-
destroy
- 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
- Specified by:
getAlgorithm
in interfaceKey
-
getOptions
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.
-
getFormat
-
getChild
-
getS
public long getS()Gets the s.- Returns:
- the s
-
getX0
public double getX0()Gets the x0.- Returns:
- the x0
-
toCertificate
Creates a certificate for encryption and decryption from thisChaosKey
. The certificate is not password protected! -
toCertificate
Creates a certificate for encryption and decryption from thisChaosKey
. The certificate is not password protected! -
toCertificate
Creates a password protected certificate for encryption and decryption from thisChaosKey
. -
toCertificate
Creates a password protected certificate for encryption and decryption from thisChaosKey
. -
toCertificate
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
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
.
-
hashCode
public int hashCode() -
equals
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 asgetOptions()
andgetChild()
). -
toString
-
createFromCertificate
- 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
Creates aChaosKey
(chain) from the password protected certificate. -
createFromCertificate
- 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
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
Creates aChaosKey
(chain) from the unsecured certificate. -
createKeyChain
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
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
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
Creates a randomChaosKey
. UsegetX0()
,getA()
andgetS()
orgetEncoded()
to retrieve the parameters of the createdChaosKey
.- Returns:
- the
ChaosKey
being initialized with random values.
-
createRndKey
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
-
createRndKey
-
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.
-
fixedLengthChildDepth
protected int fixedLengthChildDepth()Determines the number ofChaosKey
children in a row which when applied produce output of the same length as the input was. TheChaosKey
child after that determined depth is either null or a variable lengthChaosKey
child (as ofnextVariableLengthChild()
).- Returns:
- The number of
ChaosKey
children in a row which when applied produce output of the same length as the input was.
-
nextVariableLengthChild
Determines the nextChaosKey
child (excluding this) which does not(!) produce output of the same length as the input was. This is theChaosKey
child after the determined depth ofChaosKey
children in a row which when applied produce output of the same length as the input was (as offixedLengthChildDepth()
) or null if there is no such nextChaosKey
. -
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
Creates a certificate head for an unsecured certificate.- Returns:
- The accordingly created certificate head.
-
toCertificateHead
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
Creates a certificate tail for an unsecured certificate.- Returns:
- The accordingly created certificate tail.
-
toCertificateTail
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.
-