- java.lang.Object
-
- org.refcodes.forwardsecrecy.ForwardSecrecyUtility
-
public final class ForwardSecrecyUtility extends Object
The Class ForwardSecrecyUtility.
-
-
Field Summary
Fields Modifier and Type Field Description static int
CIPHER_LENGTH
static int
CIPHER_UID_LENGTH
static int
CIPHER_UID_TIMESTAMP_LENGTH
static int
MESSAGE_LENGTH
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
createCipher()
Default way on how to create a cipher.static String
createCipherUid()
Default way on how to create a cipher UID.static String
createMessage()
Default way on how to create a message which is to be signed in order to identify the owner of a public key.static boolean
hasEncryptionPattern(String aText)
Returns true in case the given text provided the characteristics of an encrypted text as of the cipher and cipher UID pattern. ------------------------------------------------------------------------- CAUTION: A plain text may have the same characteristics, an encrypted text must have these characteristics!static PrivateKey
readPrivateKey(File aFile, String aPassword)
static PublicKey
readPublicKey(File aFile)
static String
toCipherUidPrefix(String aCipherUidWithEncryptedText)
Expects a text with a prefixed cipher UID.static String
toEncryptedTextBody(String aCipherUidWithEncryptedText)
Expects a text with a prefixed cipher UID.
-
-
-
Field Detail
-
CIPHER_UID_TIMESTAMP_LENGTH
public static final int CIPHER_UID_TIMESTAMP_LENGTH
- See Also:
- Constant Field Values
-
CIPHER_UID_LENGTH
public static final int CIPHER_UID_LENGTH
- See Also:
- Constant Field Values
-
CIPHER_LENGTH
public static final int CIPHER_LENGTH
- See Also:
- Constant Field Values
-
MESSAGE_LENGTH
public static final int MESSAGE_LENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
hasEncryptionPattern
public static boolean hasEncryptionPattern(String aText)
Returns true in case the given text provided the characteristics of an encrypted text as of the cipher and cipher UID pattern. ------------------------------------------------------------------------- CAUTION: A plain text may have the same characteristics, an encrypted text must have these characteristics! -------------------------------------------------------------------------- Parameters:
aText
- The text to test whether it is encrypted.- Returns:
- True in case the given text has the characteristics of an encrypted text
-
toCipherUidPrefix
public static String toCipherUidPrefix(String aCipherUidWithEncryptedText)
Expects a text with a prefixed cipher UID. Extracts the cipher UID with which the given text was encrypted.- Parameters:
aCipherUidWithEncryptedText
- The encrypted text with the prefixed cipher UID- Returns:
- The cipher UID or null if none cipher UID was found
-
toEncryptedTextBody
public static String toEncryptedTextBody(String aCipherUidWithEncryptedText)
Expects a text with a prefixed cipher UID. Extracts the encrypted Text without the prefixed cipher UID.- Parameters:
aCipherUidWithEncryptedText
- The encrypted text with the prefixed cipher UID- Returns:
- The encrypted text portion or null if none cipher UID was found (then we have an invalid format of the provided text)
-
createCipherUid
public static String createCipherUid()
Default way on how to create a cipher UID. In case the default way generated bad cipher UIDs, the default way's implementation is changed making it good again and all system using the default way. The timestamp is prepended so that regarding on the timestamp, encrypted texts can be easily selected, e.g. texts being encrypted with a cipher older than a given timestamp.- Returns:
- A cipher UID created the default way.
-
createCipher
public static String createCipher()
Default way on how to create a cipher. In case the default way generated bad ciphers, the default way's implementation is changed making it secure again and all system using the default way.- Returns:
- A cipher created the default way.
-
createMessage
public static String createMessage()
Default way on how to create a message which is to be signed in order to identify the owner of a public key.- Returns:
- A message created the default way.
-
readPrivateKey
public static PrivateKey readPrivateKey(File aFile, String aPassword) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException
-
readPublicKey
public static PublicKey readPublicKey(File aFile) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException
-
-