|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lapetus_ltd.api.common.TLptsCryptoUtil
public class TLptsCryptoUtil
Class Description : Cryptographic module for encrypting and decrypting transportable data.
TLptsCryptoUtil myCrypto = new TLptsCryptoUtil();
myCrypto.initCipherRSA(1024);
myCrypto.defaultEncryptRSA(myData);
Nested Class Summary | |
---|---|
static class |
TLptsCryptoUtil.Credentials
This is TLptsCryptoUtil.Credentials, which is a simple class used to read and store encrypted credentials. |
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_AES_INSTANCE_STRING
The default instance string for the internal 128 bit AES Cipher (used by Cipher.getInstance). |
static int |
DEFAULT_AES_KEY_BIT_SIZE
The default key size for the internal AES key pair. |
static java.lang.String |
DEFAULT_AES_KEY_STRING
The default key string for the internal 128 bit AES Cipher (used by KeyFactory.getInstance). |
static java.lang.String |
DEFAULT_RSA_INSTANCE_STRING
The default instance string for the internal 1024 bit RSA Cipher (used by Cipher.getInstance). |
static int |
DEFAULT_RSA_KEY_BIT_SIZE
The default key size for the internal RSA key pair. |
static java.lang.String |
DEFAULT_RSA_KEY_STRING
The default key string for the internal 1024 bit RSA Cipher (used by KeyFactory.getInstance). |
Constructor Summary | |
---|---|
TLptsCryptoUtil()
This is the constructor of the Crypto module and is only used for instances of the class. |
Method Summary | |
---|---|
byte[] |
decryptAES(byte[] encrypted)
Decrypts the encrypted data with the instantiation's AES cipher. |
TLptsCryptoUtil.Credentials |
decryptCredentialsAES(byte[] encryptedData)
Decrypts credentials (user name and password) to the internal Credential format using the default AES cipher. |
TLptsCryptoUtil.Credentials |
decryptCredentialsRSA(byte[] encryptedData)
Decrypts credentials (user name and password) to the Credential class format using the default RSA cipher. |
byte[] |
decryptRSA(byte[] encrypted)
Decrypts the encrypted data with the instantiation's RSA cipher. |
static byte[] |
defaultDecryptAES(byte[] encrypted)
Decrypts the encrypted data supplied with the internal default AES Cipher. |
static TLptsCryptoUtil.Credentials |
defaultDecryptCredentialsAES(byte[] encryptedData)
Decrypts credentials (user name and password) to the Credential class format using the default AES cipher. |
static TLptsCryptoUtil.Credentials |
defaultDecryptCredentialsRSA(byte[] encryptedData)
Decrypts credentials (user name and password) to the Credential class format using the default RSA cipher. |
static byte[] |
defaultDecryptRSA(byte[] encrypted)
Decrypts the encrypted data supplied with the internal default RSA Cipher. |
static byte[] |
defaultEncryptAES(byte[] data)
Encrypts the data supplied with the internal default AES Cipher. |
static byte[] |
defaultEncryptCredentialsAES(java.lang.String user,
java.lang.String password)
Encrypts credentials (user name and password) to the internal Credential format using the default AES cipher. |
static byte[] |
defaultEncryptCredentialsRSA(java.lang.String user,
java.lang.String password)
Encrypts credentials (user name and password) to the internal Credential format using the default RSA cipher. |
static byte[] |
defaultEncryptRSA(byte[] data)
Encrypts the data supplied with the internal default RSA Cipher. |
static byte[] |
defaultForeignEncryptRSA(byte[] data)
Encrypts data with a foreign public key, so that it can be transported securely. |
static int |
defaultGetAESKeyBitSize()
Gets the bit size of the AES key. |
static java.math.BigInteger |
defaultGetPublicRSAExponent()
Gets the public key exponent from the internal default RSA key pair. |
static java.math.BigInteger |
defaultGetPublicRSAModulus()
Gets the public key modulus from the internal default RSA key pair. |
static int |
defaultGetRSAKeyBitSize()
Gets the size of the RSA key in bits. |
static boolean |
defaultInitForeignPublicCipherRSA(java.math.BigInteger modulus,
java.math.BigInteger exponent,
int keyBitLength)
Initiates the default local module so that it can encrypt data with a foreign public key. |
static boolean |
defaultInitForeignPublicCipherRSA(java.math.BigInteger modulus,
java.math.BigInteger exponent,
int keyBitLength,
java.lang.String rsaInstanceString,
java.lang.String rsaKeyString)
Initiates the default local module so that it can encrypt data with a foreign public key. |
static void |
defaultWriteAES2File(java.lang.String fileName)
Writes the default AES key to a file. |
static void |
defaultWriteRSA2Files(java.lang.String privateKeyFile,
java.lang.String publicKeyFile)
Writes the default RSA key pair to two files (private and public). |
byte[] |
encryptAES(byte[] data)
Encrypts the data with the instantiation's AES cipher. |
byte[] |
encryptCredentialsAES(java.lang.String user,
java.lang.String password)
Encrypts credentials (user name and password) to the internal Credential format using the default AES cipher. |
byte[] |
encryptCredentialsRSA(java.lang.String user,
java.lang.String password)
Encrypts credentials (user name and password) to the internal Credential format using the default RSA cipher. |
byte[] |
encryptRSA(byte[] data)
Encrypts the data with the instantiation's RSA cipher. |
byte[] |
foreignEncryptRSA(byte[] data)
Encrypts data using the foreign RSA key. |
byte[] |
generateKey4AES(int bitSize)
Generates a random key for the AES cipher. |
java.lang.String |
getAESInstanceString()
Gets the instance string used to create this instance's AES cipher. |
int |
getAESKeyBitSize()
Gets the public key modulus from the internal default RSA key pair. |
java.lang.String |
getAESKeyString()
Gets the key string used to create this instance's AES cipher. |
java.math.BigInteger |
getPublicRSAExponent()
Gets the public key modulus from the internal default RSA key pair. |
java.math.BigInteger |
getPublicRSAModulus()
Gets the public key modulus from the internal default RSA key pair. |
java.lang.String |
getRSAInstanceString()
Gets the RSA instance string used to create this instance's cipher (used by Cipher.getInstance). |
int |
getRSAKeyBitSize()
Gets the public key modulus from the internal default RSA key pair. |
java.lang.String |
getRSAKeyString()
Gets the RSA key string as sed by KeyFactory.getInstance to create the key for this cipher. |
boolean |
initCipherAES(byte[] key)
Creates and initialises the AES cipher for this module. |
boolean |
initCipherAES(byte[] key,
java.lang.String aesInstanceString,
java.lang.String aesKeyString)
Creates and initialises the AES cipher for this module. |
boolean |
initCipherAES(java.lang.String fileName)
Creates and initialises the AES cipher for this module. |
boolean |
initCipherRSA(int keyBitSize)
Initiates the RSA cryptographic capability, using the size and type supplied. |
boolean |
initCipherRSA(int keyBitSize,
java.lang.String rsaInstanceString,
java.lang.String rsaKeyString)
Initiates the RSA cryptographic capability, using the size and type supplied. |
boolean |
initCipherRSA(java.lang.String privateKeyFile,
java.lang.String publicKeyFile)
Initiates the RSA cryptographic capability, using the key pair in the files supplied. |
boolean |
initForeignPublicCipherRSA(java.math.BigInteger modulus,
java.math.BigInteger exponent,
int keyBitLength)
Initiates the foreign RSA cipher with the public key, so that encryption is possible. |
boolean |
initForeignPublicCipherRSA(java.math.BigInteger modulus,
java.math.BigInteger exponent,
int keyBitLength,
java.lang.String rsaInstanceString,
java.lang.String rsaKeyString)
Initiates the foreign RSA cipher with the public key, so that encryption is possible. |
void |
writeAES2File(java.lang.String keyFile)
Writes the AES key to a file for later use. |
void |
writeRSA2Files(java.lang.String privateKeyFile,
java.lang.String publicKeyFile)
Writes the RSA key pair to two files (private and public). |
static void |
zI()
Obfuscated, as it is not required by the application. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_AES_INSTANCE_STRING
public static final int DEFAULT_AES_KEY_BIT_SIZE
public static final java.lang.String DEFAULT_AES_KEY_STRING
public static final java.lang.String DEFAULT_RSA_INSTANCE_STRING
public static final int DEFAULT_RSA_KEY_BIT_SIZE
public static final java.lang.String DEFAULT_RSA_KEY_STRING
Constructor Detail |
---|
public TLptsCryptoUtil()
Method Detail |
---|
public byte[] decryptAES(byte[] encrypted)
Decrypts the encrypted data with the instantiation's AES cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : There is no limit to the length of the data. (unlicenced limit of 128 bytes)
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(128)) { System.out.println("Could not instantiate AES cipher!"); return; } byte[] data = initMyData(); byte[] encryptedData = cryptoModule.encryptAES(data); ... // store it or send it byte[] decryptedData = cryptoModule.decryptAES(encryptedData); ...
encrypted
- The data to be decrypted.
public TLptsCryptoUtil.Credentials decryptCredentialsAES(byte[] encryptedData)
Decrypts credentials (user name and password) to the internal Credential format using the default AES cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : The encrypted data should come from a call to encryptCredentialsRSA.
This uses the Credentials class of the TLptsCryptoUtil.
Example :
String userName = "myUser"; String password = "veryDifficultPassword"; TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(128)) { System.out.println("Could not instantiate AES cipher!"); return; } byte[] aesEncrypted = cryptoModule.encryptCredentialsAES(userName,password); TLptsCryptoUtil.Credentials aesCredentials = cryptoModule.decryptCredentialsAES(aesEncrypted); System.out.println("User Name and Password are : " + aesCredentials.userName + " & " + aesCredentials.password);
encryptedData
- The encrypted data which holds the credential information.
public TLptsCryptoUtil.Credentials decryptCredentialsRSA(byte[] encryptedData)
Decrypts credentials (user name and password) to the Credential class format using the default RSA cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : The encrypted data should come from a call to encryptCredentialsRSA.
This uses the Credentials class of the TLptsCryptoUtil.
Example :
String userName = "myUser"; String password = "veryDifficultPassword"; TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherRSA(1024)) { System.out.println("Could not instantiate RSA cipher!"); return; } byte[] rsaEncrypted = cryptoModule.encryptCredentialsRSA(userName,password); TLptsCryptoUtil.Credentials rsaCredentials = cryptoModule.decryptCredentialsRSA(rsaEncrypted); System.out.println("User Name and Password are : " + rsaCredentials.userName + " & " + rsaCredentials.password);
encryptedData
- The data previously encrypted by
public byte[] decryptRSA(byte[] encrypted)
Decrypts the encrypted data with the instantiation's RSA cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : There is no limit to the length of the data. (unlicenced limit of 128 bytes)
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherRSA(1024)) { System.out.println("Could not instantiate RSA cipher!"); return; } byte[] data = initMyData(); byte[] encryptedData = cryptoModule.encryptRSA(data); ... // store it or send it byte[] decryptedData = cryptoModule.decryptRSA(encryptedData); ...
encrypted
- The data to be decrypted.
public static byte[] defaultDecryptAES(byte[] encrypted)
Decrypts the encrypted data supplied with the internal default AES Cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : There is no limit to the length of the data. (unlicenced limit of 128 bytes)
Example :
byte[] myData = new byte[2048]; .. initialise myData byte[] encryptedData = TLptsCryptoUtil.defaultEncryptAES(myData); byte[] decryptedData = TLptsCryptoUtil.defaultDecryptAES(encryptedData); Result: myData = decryptedData
encrypted
- The encrypted data from the default AES Cipher.
TLptsLogger
for logger error.public static TLptsCryptoUtil.Credentials defaultDecryptCredentialsAES(byte[] encryptedData)
Decrypts credentials (user name and password) to the Credential class format using the default AES cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : The encrypted data should come from a call to defaultEncryptCredentialsAES.
This uses the Credentials class of the TLptsCryptoUtil.
Example :
String userName = "myUser"; String password = "veryDifficultPassword"; byte[] aesEncrypted = TLptsCryptoUtil.defaultEncryptCredentialsAES(userName,password); TLptsCryptoUtil.Credentials aesDefaultCredentials = TLptsCryptoUtil.defaultDecryptCredentialsAES(aesEncrypted); System.out.println("User Name and Password are : " + aesDefaultCredentials.userName + " & " + aesDefaultCredentials.password);
encryptedData
- The data previously encrypted by
public static TLptsCryptoUtil.Credentials defaultDecryptCredentialsRSA(byte[] encryptedData)
Decrypts credentials (user name and password) to the Credential class format using the default RSA cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : The encrypted data should come from a call to defaultEncryptCredentialsRSA.
This uses the Credentials class of the TLptsCryptoUtil.
Example :
String userName = "myUser"; String password = "veryDifficultPassword"; byte[] rsaEncrypted = TLptsCryptoUtil.defaultEncryptCredentialsRSA(userName,password); TLptsCryptoUtil.Credentials rsaDefaultCredentials = TLptsCryptoUtil.defaultDecryptCredentialsRSA(rsaEncrypted); System.out.println("User Name and Password are : " + rsaDefaultCredentials.userName + " & " + rsaDefaultCredentials.password);
encryptedData
- The data previously encrypted by defaultEncryptCredentialsRSA
public static byte[] defaultDecryptRSA(byte[] encrypted)
Decrypts the encrypted data supplied with the internal default RSA Cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : There is no limit to the length of the data. (unlicenced limit of 128 bytes)
Example :
byte[] myData = new byte[2048]; .. initialise myData byte[] encryptedData = TLptsCryptoUtil.defaultEncryptRSA(myData); byte[] decryptedData = TLptsCryptoUtil.defaultDecryptRSA(encryptedData); Result: myData = decryptedData
encrypted
- The encrypted data from the default RSA Cipher.
TLptsLogger
for logger error.public static byte[] defaultEncryptAES(byte[] data)
Encrypts the data supplied with the internal default AES Cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : There is no limit to the length of the data. (unlicenced limit of 128 bytes)
Example :
byte[] myData = new byte[2048]; .. initialise myData byte[] encryptedData = TLptsCryptoUtil.defaultEncryptAES(myData); byte[] decryptedData = TLptsCryptoUtil.defaultDecryptAES(encryptedData); Result: myData = decryptedData
data
- The data that should be encrypted.
TLptsLogger
for logger error.public static byte[] defaultEncryptCredentialsAES(java.lang.String user, java.lang.String password)
Encrypts credentials (user name and password) to the internal Credential format using the default AES cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : The encrypted data can only be read by defaultDecryptCredentialsAES.
Example :
String userName = "myUser"; String password = "veryDifficultPassword"; byte[] aesEncrypted = TLptsCryptoUtil.defaultEncryptCredentialsAES(userName,password); TLptsCryptoUtil.Credentials aesDefaultCredentials = TLptsCryptoUtil.defaultDecryptCredentialsAES(aesEncrypted); System.out.println("User Name and Password are : " + aesDefaultCredentials.userName + " & " + aesDefaultCredentials.password);
user
- The user name string to be encrypted together with the password.password
- The password string to be encrypted together with the user name.
public static byte[] defaultEncryptCredentialsRSA(java.lang.String user, java.lang.String password)
Encrypts credentials (user name and password) to the internal Credential format using the default RSA cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : The encrypted data can only be read by defaultDecryptCredentialsRSA.
Example :
String userName = "myUser"; String password = "veryDifficultPassword"; byte[] rsaEncrypted = TLptsCryptoUtil.defaultEncryptCredentialsRSA(userName,password); TLptsCryptoUtil.Credentials rsaDefaultCredentials = TLptsCryptoUtil.defaultDecryptCredentialsRSA(rsaEncrypted); System.out.println("User Name and Password are : " + rsaDefaultCredentials.userName + " & " + rsaDefaultCredentials.password);
user
- The user name string to be encrypted together with the password.password
- The password string to be encrypted together with the user name.
public static byte[] defaultEncryptRSA(byte[] data)
Encrypts the data supplied with the internal default RSA Cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : There is no limit to the length of the data. (unlicenced limit of 128 bytes)
Example :
byte[] myData = new byte[2048]; .. initialise myData byte[] encryptedData = TLptsCryptoUtil.defaultEncryptRSA(myData); byte[] decryptedData = TLptsCryptoUtil.defaultDecryptRSA(encryptedData); Result: myData = decryptedData
data
- The data that should be encrypted.
TLptsLogger
for logger error.public static byte[] defaultForeignEncryptRSA(byte[] data)
Encrypts data with a foreign public key, so that it can be transported securely.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : Use this as part of initialising a foreign key for encryption.
Example :
// somewhere else on this lovely planet of ours TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048, "RSA/ECB/PKCS1Padding","RSA"); // at our humble dwelling TLptsCryptoUtil.defaultInitForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize(), foreignCrypto.getRSAInstanceString(), foreignCrypto.getRSAKeyString()); byte[] encryptedData = TLptsCryptoUtil.defaultForeignEncryptRSA(data); // back at that lovely place mentioned earlier byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
data
- The local data to encrypt with the foreign public key.
TLptsLogger
for logger error.public static int defaultGetAESKeyBitSize()
Gets the bit size of the AES key.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes : This is just used for output to the user.
Example :
int aesKeySize = TLptsCryptoUtil.defaultGetAESKeyBitSize(); System.out.println("The AES key is " + aesKeySize + " bits in length");
public static java.math.BigInteger defaultGetPublicRSAExponent()
Gets the public key exponent from the internal default RSA key pair.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : Use this as part of initialising a foreign key for encryption.
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); // on this end of the pond sendOurLocalComponents(TLptsCryptoUtil.defaultGetPublicRSAModulus(), TLptsCryptoUtil.defaultGetPublicRSAExponent(), TLptsCryptoUtil.DEFAULT_RSA_KEY_BIT_SIZE, TLptsCryptoUtil.DEFAULT_RSA_INSTANCE_STRING, TLptsCryptoUtil.DEFAULT_RSA_KEY_STRING ); // back on the other end of the pond BigInteger theirModulus = readTheirModulus(); BigInteger theirExponent = readTheirExponent(); int theirKeySize = readTheirKeySize(); String theirInstanceString = readTheirInstanceString(); String theirKeyString = readTheirKeyString(); foreignCrypto.initForeignPublicCipherRSA(theirModulus, theirExponent , theirKeySize , theirInstanceString , theirKeyString ); byte[] encryptedData = foreignCrypto.foreignEncryptRSA(data); // On this end of the pond we can decrypt byte[] decryptedData = TLptsCryptoUtil.defaultDecryptRSA(encryptedData); ...
public static java.math.BigInteger defaultGetPublicRSAModulus()
Gets the public key modulus from the internal default RSA key pair.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : Use this as part of initialising a foreign key for encryption.
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); // on this end of the pond sendOurLocalComponents(TLptsCryptoUtil.defaultGetPublicRSAModulus(), TLptsCryptoUtil.defaultGetPublicRSAExponent(), TLptsCryptoUtil.DEFAULT_RSA_KEY_BIT_SIZE, TLptsCryptoUtil.DEFAULT_RSA_INSTANCE_STRING, TLptsCryptoUtil.DEFAULT_RSA_KEY_STRING ); // back on the other end of the pond BigInteger theirModulus = readTheirModulus(); BigInteger theirExponent = readTheirExponent(); int theirKeySize = readTheirKeySize(); String theirInstanceString = readTheirInstanceString(); String theirKeyString = readTheirKeyString(); foreignCrypto.initForeignPublicCipherRSA(theirModulus, theirExponent , theirKeySize , theirInstanceString , theirKeyString ); byte[] encryptedData = foreignCrypto.foreignEncryptRSA(data); // On this end of the pond we can decrypt byte[] decryptedData = TLptsCryptoUtil.defaultDecryptRSA(encryptedData); ...
public static int defaultGetRSAKeyBitSize()
Gets the size of the RSA key in bits.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes : Use this as part of the initiation of a foreign key.
Example :
// somewhere else on this lovely planet of ours TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048, "RSA/ECB/PKCS1Padding","RSA"); // at our humble dwelling TLptsCryptoUtil.defaultInitForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize(), foreignCrypto.getRSAInstanceString(), foreignCrypto.getRSAKeyString()); byte[] encryptedData = TLptsCryptoUtil.defaultForeignEncryptRSA(data); // back at that lovely place mentioned earlier byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
public static boolean defaultInitForeignPublicCipherRSA(java.math.BigInteger modulus, java.math.BigInteger exponent, int keyBitLength)
Initiates the default local module so that it can encrypt data with a foreign public key.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes : Use this if the other crypto has initialised with the default instance and key strings. ("RSA","RSA")
If not, then use the other Init function where the strings can be specified.
Function disabled in unlicenced version.
Example :
// somewhere else on this lovely planet of ours TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048); // default Cipher instance TLptsCryptoUtil.DEFAULT_RSA_INSTANCE_STRING // at our humble dwelling TLptsCryptoUtil.defaultInitForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize()); byte[] encryptedData = TLptsCryptoUtil.defaultForeignEncryptRSA(data); // back at that lovely place mentioned earlier byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
modulus
- The foreign modulus. If this is coming over the wire as byte[], create this parameter with 'new BigInteger(byte[])';
Use BigInteger.toByteArray() to send this.exponent
- The exponent part of the foreign public key. The same applies here for initialising or getting the bytes.keyBitLength
- The key length in bits.
public static boolean defaultInitForeignPublicCipherRSA(java.math.BigInteger modulus, java.math.BigInteger exponent, int keyBitLength, java.lang.String rsaInstanceString, java.lang.String rsaKeyString)
Initiates the default local module so that it can encrypt data with a foreign public key.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes : Use this to initialise a foreign specialised (ie not default) cipher.
Function disabled in unlicenced version.
Example :
// somewhere else on this lovely planet of ours TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048, "RSA/ECB/PKCS1Padding","RSA"); // at our humble dwelling TLptsCryptoUtil.defaultInitForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize(), foreignCrypto.getRSAInstanceString(), foreignCrypto.getRSAKeyString()); byte[] encryptedData = TLptsCryptoUtil.defaultForeignEncryptRSA(data); // back at that lovely place mentioned earlier byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
modulus
- The foreign modulus. If this is coming over the wire as byte[], create this parameter with 'new BigInteger(byte[])';
Use BigInteger.toByteArray() to send this.exponent
- The exponent part of the foreign public key. The same applies here for initialising or getting the bytes.keyBitLength
- The key length in bits.rsaInstanceString
- The instantiation string to use for the Cipher. (used by Cipher.getInstance)rsaKeyString
- The instantiation string to use for the Key. (used by KeyFactory.getInstance)
public static void defaultWriteAES2File(java.lang.String fileName)
Writes the default AES key to a file.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes : The default key can be written, but it cannot be loaded into the static default crypto.
A new instance is required for loading the saved key.
Example :
TLptsCryptoUtil.defaultWriteAES2File(TLptsFileUtil.getUserHomeLapetusDirectory() + "aes.default.key.xml"); TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(TLptsFileUtil.getUserHomeLapetusDirectory() + "aes.default.key.xml")) System.out.println("Could not initiate an instance of the crypto module with the default AES key.");
fileName
- The path of the file that will hold the key in xml hexadecimal format.public static void defaultWriteRSA2Files(java.lang.String privateKeyFile, java.lang.String publicKeyFile)
Writes the default RSA key pair to two files (private and public).
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes : The default keys can be written, but they cannot be loaded into the static default crypto.
A new instance is required for loading the saved keys.
Example :
TLptsCryptoUtil.defaultWriteRSA2Files(TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.private.key.xml", TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.public.key.xml"); TLptsCryptoUtil anotherCryptoModule = new TLptsCryptoUtil(); if (!anotherCryptoModule.initCipherRSA(TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.private.key.xml", TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.public.key.xml")) { System.out.println("Could not instantiate RSA cipher from file!"); return; }
privateKeyFile
- The full path of the file to save the private key. (keep this file, not to be shared)publicKeyFile
- The full path of the file to save the public key. (give this file to others for encrypting data that only you can read)public byte[] encryptAES(byte[] data)
Encrypts the data with the instantiation's AES cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : There is no limit to the length of the data. (unlicenced limit of 128 bytes)
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(128)) { System.out.println("Could not instantiate AES cipher!"); return; } byte[] data = initMyData(); byte[] encryptedData = cryptoModule.encryptAES(data); ... // store it or send it byte[] decryptedData = cryptoModule.decryptAES(encryptedData); ...
data
- The data to be encrypted.
public byte[] encryptCredentialsAES(java.lang.String user, java.lang.String password)
Encrypts credentials (user name and password) to the internal Credential format using the default AES cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : The encrypted data can only be read by defaultDecryptCredentialsAES.
Example :
String userName = "myUser"; String password = "veryDifficultPassword"; TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(128)) { System.out.println("Could not instantiate AES cipher!"); return; } byte[] aesEncrypted = cryptoModule.encryptCredentialsAES(userName,password); TLptsCryptoUtil.Credentials aesCredentials = cryptoModule.decryptCredentialsAES(aesEncrypted); System.out.println("User Name and Password are : " + aesCredentials.userName + " & " + aesCredentials.password);
user
- The user name string to be encrypted together with the password.password
- The password string to be encrypted together with the user name.
public byte[] encryptCredentialsRSA(java.lang.String user, java.lang.String password)
Encrypts credentials (user name and password) to the internal Credential format using the default RSA cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : The encrypted data can only be read by decryptCredentialsRSA.
Example :
String userName = "myUser"; String password = "veryDifficultPassword"; TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherRSA(1024)) { System.out.println("Could not instantiate RSA cipher!"); return; } byte[] rsaEncrypted = cryptoModule.encryptCredentialsRSA(userName,password); TLptsCryptoUtil.Credentials rsaCredentials = cryptoModule.decryptCredentialsRSA(rsaEncrypted); System.out.println("User Name and Password are : " + rsaCredentials.userName + " & " + rsaCredentials.password);
user
- The user name string to be encrypted together with the password.password
- The password string to be encrypted together with the user name.
public byte[] encryptRSA(byte[] data)
Encrypts the data with the instantiation's RSA cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : There is no limit to the length of the data. (unlicenced limit of 128 bytes)
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherRSA(4096)) // pretty large key { System.out.println("Could not instantiate RSA cipher!"); return; } byte[] data = initMyData(); byte[] encryptedData = cryptoModule.encryptRSA(data); ... // store it or send it byte[] decryptedData = cryptoModule.decryptRSA(encryptedData); ...
data
- The data to be encrypted.
public byte[] foreignEncryptRSA(byte[] data)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : There is no limit to the length of the data. (unlicenced version returns null)
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048); // on this end of the pond TLptsCryptoUtil localCrypto = new TLptsCryptoUtil(); localCrypto.initForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize()); byte[] encryptedData = localCrypto.foreignEncryptRSA(data); // back on the other end of the pond byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
data
- The data to be encrypted.
public byte[] generateKey4AES(int bitSize)
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes.
Notes : Use this every time a new cipher is created. Useful in generating a new key for every communication session.
In the example below there are log messages for the attempts to create 256 and 192 bit ciphers (if they are not successful).
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(cryptoModule.generateKey4AES(256))) // may not be able to do this if (!cryptoModule.initCipherAES(cryptoModule.generateKey4AES(192))) // may not be able to do this if (!cryptoModule.initCipherAES(cryptoModule.generateKey4AES(128))) // should be able to do this { System.out.println("Could not generate at least a 128 bit key for AES"); return; }
bitSize
- Either 128, 192 or 256.
public java.lang.String getAESInstanceString()
Gets the instance string used to create this instance's AES cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes, but is initialised internally to "AES/ECB/PKCS5Padding". Could be changed by initCipherAES.
Notes :
Example :
TLptsCryptoUtil crypto = new TLptsCryptoUtil(); crypto.initCipherAES(128,"AES","AES"); System.out.println("AES Key Bit Size = " + cryptoModule.getAESKeyBitSize()); System.out.println("AES Instance String = " + cryptoModule.getAESInstanceString()); System.out.println("AES Key String = " + cryptoModule.getAESKeyString()); ... Result : AES Key Bit Size = 128 AES Instance String = AES // not default AES Key String = AES
public int getAESKeyBitSize()
Gets the public key modulus from the internal default RSA key pair.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : Use this as part of initialising a foreign key for encryption.
Example :
TLptsCryptoUtil crypto = new TLptsCryptoUtil(); crypto.initCipherAES(128,"AES","AES"); System.out.println("AES Key Bit Size = " + cryptoModule.getAESKeyBitSize()); System.out.println("AES Instance String = " + cryptoModule.getAESInstanceString()); System.out.println("AES Key String = " + cryptoModule.getAESKeyString()); ... Result : AES Key Bit Size = 128 AES Instance String = AES // not standard AES Key String = AES
public java.lang.String getAESKeyString()
Gets the key string used to create this instance's AES cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes, but is initialised internally to "AES". Could be changed by initCipherAES.
Notes :
Example :
TLptsCryptoUtil crypto = new TLptsCryptoUtil(); crypto.initCipherAES(128,"AES","AES"); System.out.println("AES Key Bit Size = " + cryptoModule.getAESKeyBitSize()); System.out.println("AES Instance String = " + cryptoModule.getAESInstanceString()); System.out.println("AES Key String = " + cryptoModule.getAESKeyString()); ... Result : AES Key Bit Size = 128 AES Instance String = AES // not standard AES Key String = AES
public java.math.BigInteger getPublicRSAExponent()
Gets the public key modulus from the internal default RSA key pair.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : Use this as part of initialising a foreign key for encryption.
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048); // on this end of the pond TLptsCryptoUtil localCrypto = new TLptsCryptoUtil(); localCrypto.initForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize(), foreignCrypto.getRSAInstanceString(), foreignCrypto.getRSAKeyString()); byte[] encryptedData = localCrypto.foreignEncryptRSA(data); // back on the other end of the pond byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
public java.math.BigInteger getPublicRSAModulus()
Gets the public key modulus from the internal default RSA key pair.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : Use this as part of initialising a foreign key for encryption.
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048); // on this end of the pond TLptsCryptoUtil localCrypto = new TLptsCryptoUtil(); localCrypto.initForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize(), foreignCrypto.getRSAInstanceString(), foreignCrypto.getRSAKeyString()); byte[] encryptedData = localCrypto.foreignEncryptRSA(data); // back on the other end of the pond byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
public java.lang.String getRSAInstanceString()
Gets the RSA instance string used to create this instance's cipher (used by Cipher.getInstance).
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes, but is initialised internally to "RSA". Could be changed by initCipherRSA.
Notes : Use this as part of initialising a foreign key for encryption.
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048); // on this end of the pond TLptsCryptoUtil localCrypto = new TLptsCryptoUtil(); localCrypto.initForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize(), foreignCrypto.getRSAInstanceString(), foreignCrypto.getRSAKeyString()); byte[] encryptedData = localCrypto.foreignEncryptRSA(data); // back on the other end of the pond byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
public int getRSAKeyBitSize()
Gets the public key modulus from the internal default RSA key pair.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes
Notes : Use this as part of initialising a foreign key for encryption.
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048); // on this end of the pond TLptsCryptoUtil localCrypto = new TLptsCryptoUtil(); localCrypto.initForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize(), foreignCrypto.getRSAInstanceString(), foreignCrypto.getRSAKeyString()); byte[] encryptedData = localCrypto.foreignEncryptRSA(data); // back on the other end of the pond byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
public java.lang.String getRSAKeyString()
Gets the RSA key string as sed by KeyFactory.getInstance to create the key for this cipher.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : Yes, but is initialised internally to "RSA". Could be changed by initCipherRSA.
Notes : Use this as part of initialising a foreign key for encryption.
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048); // on this end of the pond TLptsCryptoUtil localCrypto = new TLptsCryptoUtil(); localCrypto.initForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize(), foreignCrypto.getRSAInstanceString(), foreignCrypto.getRSAKeyString()); byte[] encryptedData = localCrypto.foreignEncryptRSA(data); // back on the other end of the pond byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
public boolean initCipherAES(byte[] key)
Creates and initialises the AES cipher for this module.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A.
Notes :
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(cryptoModule.generateKey4AES(256))) // may not be able to do this if (!cryptoModule.initCipherAES(cryptoModule.generateKey4AES(192))) // may not be able to do this if (!cryptoModule.initCipherAES(cryptoModule.generateKey4AES(128))) // should be able to do this { System.out.println("Could not generate at least a 128 bit key for AES"); return; }
key
- The key to use for creating this cipher.
public boolean initCipherAES(byte[] key, java.lang.String aesInstanceString, java.lang.String aesKeyString)
Creates and initialises the AES cipher for this module.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A.
Notes : In the example below the cipher created can only be used for encrypted data up to the block size of the cipher.
The block size is normally the size of the key for the AES cipher, so the cipher below will report a padding error if the data is larger than 16 bytes.
To solve this the instance string should be "AES/ECB/PKCS5Padding", which allows the crypto module to chain endless amounts of blocks for encryption.
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(cryptoModule.generateKey4AES(128),"AES","AES")) { System.out.println("Could not instantiate AES cipher!"); return; }
key
- The key to use for creating this cipher.aesInstanceString
- Format "AES/Blocking/Padding". The default is "AES/ECB/PKCS5Padding". (used by Cipher.getInstance)aesKeyString
- Default is "AES". (used by KeyFactory.getInstance)
public boolean initCipherAES(java.lang.String fileName)
Creates and initialises the AES cipher for this module.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A.
Notes : The instance string and key string (used by Cipher.getInstance and KeyFactory.getInstance) are taken from the key file
and used to initiate the cipher. (which emulates the cipher that was used to save the file)
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(TLptsFileUtil.getUserHomeLapetusDirectory() + "my.aes.key.xml")) { System.out.println("Could not instantiate AES cipher!"); return; } System.out.println("AES Key Bit Size = " + cryptoModule.getAESKeyBitSize()); System.out.println("AES Instance String = " + cryptoModule.getAESInstanceString()); System.out.println("AES Key String = " + cryptoModule.getAESKeyString());
fileName
- The path to the xml key file, which must have the root element XLptsCipherKeyType. (normally created with writeAES2File)
public boolean initCipherRSA(int keyBitSize)
Initiates the RSA cryptographic capability, using the size and type supplied.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : n/a Notes : Example :TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherRSA(4096)) / initiated with "RSA" and "RSA" { System.out.println("Could not instantiate RSA cipher!"); return; }
keyBitSize
- Either 512, 1024, 2048 or 4096.
public boolean initCipherRSA(int keyBitSize, java.lang.String rsaInstanceString, java.lang.String rsaKeyString)
Initiates the RSA cryptographic capability, using the size and type supplied.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : n/a Notes : Example :TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherRSA(1024,"RSA/ECB/PKCS1Padding","RSA")) { System.out.println("Could not instantiate RSA cipher!"); return; }
keyBitSize
- Either 512, 1024, 2048 or 4096.rsaInstanceString
- Format "RSA/Blocking/Padding". The default is "RSA".rsaKeyString
- Default is "RSA".
public boolean initCipherRSA(java.lang.String privateKeyFile, java.lang.String publicKeyFile)
Initiates the RSA cryptographic capability, using the key pair in the files supplied.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : n/a Notes : Example :TLptsCryptoUtil.defaultWriteRSA2Files(TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.private.key.xml", TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.public.key.xml"); TLptsCryptoUtil anotherCryptoModule = new TLptsCryptoUtil(); if (!anotherCryptoModule.initCipherRSA(TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.private.key.xml", TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.public.key.xml")) { System.out.println("Could not instantiate RSA cipher from file!"); return; }
privateKeyFile
- The xml file with the element XLptsCipherKeyType that contains the private key of the RSA key pair.publicKeyFile
- The XLptsCipherKeyType element xml file with the public key of the RSA key pair.
public boolean initForeignPublicCipherRSA(java.math.BigInteger modulus, java.math.BigInteger exponent, int keyBitLength)
Initiates the foreign RSA cipher with the public key, so that encryption is possible.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A.
Notes : Use this as part of initialising a foreign key for encryption. (unlicenced version returns false)
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048); // on this end of the pond TLptsCryptoUtil localCrypto = new TLptsCryptoUtil(); localCrypto.initForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize());, byte[] encryptedData = localCrypto.foreignEncryptRSA(data); // back on the other end of the pond byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
modulus
- The foreign modulus. If this is coming over the wire as byte[], create this parameter with 'new BigInteger(byte[])';
Use BigInteger.toByteArray() to send this.exponent
- The exponent part of the foreign public key. The same applies here for initialising or getting the bytes.keyBitLength
- The bit length of the foreign cipher.
public boolean initForeignPublicCipherRSA(java.math.BigInteger modulus, java.math.BigInteger exponent, int keyBitLength, java.lang.String rsaInstanceString, java.lang.String rsaKeyString)
Initiates the foreign RSA cipher with the public key, so that encryption is possible.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A.
Notes : Use this as part of initialising a foreign key for encryption. (unlicenced version returns false)
Example :
// somewhere on the other side of the pond TLptsCryptoUtil foreignCrypto = new TLptsCryptoUtil(); foreignCrypto.initCipherRSA(2048); // on this end of the pond TLptsCryptoUtil localCrypto = new TLptsCryptoUtil(); localCrypto.initForeignPublicCipherRSA(foreignCrypto.getPublicRSAModulus(), foreignCrypto.getPublicRSAExponent(), foreignCrypto.getRSAKeyBitSize(), foreignCrypto.getRSAInstanceString(), foreignCrypto.getRSAKeyString()); byte[] encryptedData = localCrypto.foreignEncryptRSA(data); // back on the other end of the pond byte[] decryptedData = foreignCrypto.decryptRSA(encryptedData); ...
modulus
- The foreign modulus. If this is coming over the wire as byte[], create this parameter with 'new BigInteger(byte[])';
Use BigInteger.toByteArray() to send this.exponent
- The exponent part of the foreign public key. The same applies here for initialising or getting the bytes.keyBitLength
- The bit length of the foreign cipher.rsaInstanceString
- Format "RSA/Blocking/Padding". The default is "RSA".rsaKeyString
- Default is "RSA".
public void writeAES2File(java.lang.String keyFile)
Writes the AES key to a file for later use.
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherAES(128)) { System.out.println("Could not instantiate AES cipher!"); return; } cryptoModule.writeAES2File(TLptsFileUtil.getUserHomeLapetusDirectory() + "aes.default.key.xml"); TLptsCryptoUtil anotherCryptoModule = new TLptsCryptoUtil(); if (!anotherCryptoModule.initCipherAES(TLptsFileUtil.getUserHomeLapetusDirectory() + "aes.default.key.xml")) System.out.println("Could not initiate an instance of the crypto module with the AES key.");
keyFile
- The path of the file that will hold the key in xml hexadecimal format (XLptsCipherKeyType element)public void writeRSA2Files(java.lang.String privateKeyFile, java.lang.String publicKeyFile)
Writes the RSA key pair to two files (private and public).
Thread Safe : Yes
Spawns its own Thread : No
May Return NULL : N/A
Notes :
Example :
TLptsCryptoUtil cryptoModule = new TLptsCryptoUtil(); if (!cryptoModule.initCipherRSA(2048)) { System.out.println("Could not instantiate RSA cipher!"); return; } cryptoModule.writeRSA2Files(TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.private.key.xml", TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.public.key.xml"); TLptsCryptoUtil anotherCryptoModule = new TLptsCryptoUtil(); if (!anotherCryptoModule.initCipherRSA(TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.private.key.xml", TLptsFileUtil.getUserHomeLapetusDirectory() + "rsa.default.public.key.xml")) { System.out.println("Could not instantiate RSA cipher from file!"); return; }
privateKeyFile
- The full path of the file to save the private key. (keep this file, not to be shared)publicKeyFile
- The full path of the file to save the public key. (give this file to others for encrypting data that only you can read)public static void zI()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |