public class CryptoUtils
extends java.lang.Object
Constructor and Description |
---|
CryptoUtils()
Constructor method for i18n purposes only.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
assembleUserID(java.lang.String realname,
java.lang.String comment,
java.lang.String email)
Combines the user ID fields real name (optional), comment (optional), and e-mail.
|
static java.util.Date |
calculateExpireDate(java.util.Date creation,
int validdays)
Computes the expiration date of a key.
|
static int |
checkEncryptionASCIIFormat(byte[] encrypted)
Checks the format of the given encrypted ASCII-armored data.
|
static java.lang.String |
convertKeyID(long longkeyid)
Converts the given key identifier to hexadecimal format as used for PGP.
|
static long |
convertKeyID(java.lang.String keyid)
Converts the given key identifier back to the numeric representation.
|
static byte[] |
decryptAES(byte[] encrypted,
byte[] aeskey,
boolean armor)
Encrypts the given data portion using the given AES key.
|
static boolean |
decryptAES(java.io.InputStream istream,
java.io.OutputStream ostream,
byte[] aeskey)
Decrypts the given data portion using the given AES key.
|
static byte[] |
encryptAES(byte[] rawdata,
byte[] aeskey,
boolean armor)
Encrypts the given data portion using the given AES key.
|
static boolean |
encryptAES(java.io.InputStream istream,
java.io.OutputStream ostream,
byte[] aeskey)
Encrypts the given data portion using the given AES key.
|
static java.lang.String |
extractComment(java.lang.String userid)
Extracts the comment from the given user ID.
|
static java.lang.String |
extractEMail(java.lang.String userid)
Extracts the email from the given user ID.
|
static java.lang.String |
extractRealName(java.lang.String userid)
Extracts the real name from the given user ID.
|
static java.lang.String |
getChecksum(java.lang.String algo,
byte[] data)
Calculates a checksum for binary data.
|
static java.lang.String[] |
getDefaultCompressionAlgos()
Provides the default compression algorithms for key generation.
|
static java.lang.String[] |
getDefaultHashingAlgos()
Provides the default hashing algorithms for key generation.
|
static java.lang.String[] |
getDefaultSymmetricKeyAlgos()
Provides the default symmetric key algorithms for key generation.
|
static byte[] |
getDetachedSignature(org.bouncycastle.openpgp.PGPSignature signature,
boolean armor,
java.lang.String version)
Creates a binary representation of a given detached signature.
|
static java.lang.String[] |
getEncryptionKeyIDs(java.io.InputStream istream)
Reads the key IDs of the keys used for an encrypted file.
|
static java.lang.String |
getMD5Checksum(byte[] data)
Calculates a MD5 checksum for binary data.
|
static java.lang.String |
getSHA1Checksum(byte[] data)
Calculates a SHA-1 checksum for binary data.
|
static org.bouncycastle.openpgp.PGPSignature[] |
loadDetachedSignatures(java.io.InputStream sigstream)
Extracts detached signatures from a stream containing one or multiple detached signatures.
|
static java.util.Vector<java.lang.String> |
loadDetachedSignaturesASCII(java.io.InputStream sigstream)
Parses an ASCII-armored stream containing one or multiple detached signatures.
|
static void |
main(java.lang.String[] arg)
This may be used especially for debugging purposes.
|
static java.io.File |
mapToDecryptedFile(java.io.File encrypted)
Provides the appropriate name of a decrypted file based on the encrypted file name.
|
protected static PasswordDialog |
showPasswordDialog(java.awt.Component parent,
java.lang.String userid,
boolean remember)
Shows the password dialog to prompt the user for a valid PGP key passphrase.
|
public CryptoUtils() throws java.lang.InstantiationException
I18NExtractor
).
java.lang.InstantiationException
- Error indicationpublic static java.lang.String getMD5Checksum(byte[] data)
data
- Binary datanull
public static java.lang.String getSHA1Checksum(byte[] data)
data
- Binary datanull
public static java.lang.String getChecksum(java.lang.String algo, byte[] data)
algo
- The algorithm like "MD5"data
- Binary datanull
public static java.lang.String convertKeyID(long longkeyid)
longkeyid
- Binary datanull
otherwiseconvertKeyID(String)
public static long convertKeyID(java.lang.String keyid)
keyid
- Display data like 0xaabbccddconvertKeyID(long)
public static java.io.File mapToDecryptedFile(java.io.File encrypted)
encrypted
- The encrypted filepublic static java.lang.String[] getEncryptionKeyIDs(java.io.InputStream istream)
istream
- The encrypted data stream to be analyzed, never closednull
indicates errorconvertKeyID(String)
public static java.lang.String extractRealName(java.lang.String userid)
userid
- The user ID to be analyzednull
public static java.lang.String extractComment(java.lang.String userid)
userid
- The user ID to be analyzednull
public static java.lang.String extractEMail(java.lang.String userid)
userid
- The user ID to be analyzednull
public static byte[] encryptAES(byte[] rawdata, byte[] aeskey, boolean armor)
rawdata
- The data to be encryptedaeskey
- The key to use (128, 192, or 256 length)armor
- ASCII-armored?null
indicates errorpublic static boolean encryptAES(java.io.InputStream istream, java.io.OutputStream ostream, byte[] aeskey)
istream
- The data to be encrypted, never closedostream
- The encrypted data, never closedaeskey
- The key to use (128, 192, or 256 bits length)public static byte[] decryptAES(byte[] encrypted, byte[] aeskey, boolean armor)
encrypted
- The encrypted dataaeskey
- The key to use (128, 192, or 256 length)armor
- Expect ASCII-armored?null
indicates errorpublic static boolean decryptAES(java.io.InputStream istream, java.io.OutputStream ostream, byte[] aeskey)
istream
- The data to be decrypted, never closedostream
- The decrypted data, never closedaeskey
- The key to use (128, 192, or 256 bits length)public static int checkEncryptionASCIIFormat(byte[] encrypted)
encrypted
- The encrypted ASCII-armored dataCryptoConstants.FORMAT_PGP_ARMOR
, ...public static java.util.Date calculateExpireDate(java.util.Date creation, int validdays)
creation
- The key creation datevaliddays
- Number of days the key is validnull
= key does never expirepublic static java.lang.String assembleUserID(java.lang.String realname, java.lang.String comment, java.lang.String email)
realname
- The real name (optional)comment
- The comment (optional)email
- The e-mail addressnull
java.lang.NullPointerException
- If a parameter is null
public static java.lang.String[] getDefaultHashingAlgos()
public static java.lang.String[] getDefaultCompressionAlgos()
public static java.lang.String[] getDefaultSymmetricKeyAlgos()
protected static PasswordDialog showPasswordDialog(java.awt.Component parent, java.lang.String userid, boolean remember)
parent
- The GUI parent for the dialoguserid
- The key ID to printremember
- Remember the passphrase for the next time?null
if not availablepublic static java.util.Vector<java.lang.String> loadDetachedSignaturesASCII(java.io.InputStream sigstream)
sigstream
- The signature stream, closed herepublic static org.bouncycastle.openpgp.PGPSignature[] loadDetachedSignatures(java.io.InputStream sigstream)
sigstream
- The signature streampublic static byte[] getDetachedSignature(org.bouncycastle.openpgp.PGPSignature signature, boolean armor, java.lang.String version)
signature
- The pre-processed signature objectarmor
- Generate ASCII formatversion
- The version info (optional)null
indicates errorpublic static void main(java.lang.String[] arg) throws java.lang.Exception
arg
- Array of String
objects with console paramsjava.lang.Exception
- Error indicationCopyright © 2005-2023 Leisenfels GmbH. All rights reserved.