Package com.browserup.bup.mitm.util
Class EncryptionUtil
- java.lang.Object
-
- com.browserup.bup.mitm.util.EncryptionUtil
-
public class EncryptionUtil extends java.lang.ObjectA collection of simple JCA-related utilities.
-
-
Constructor Summary
Constructors Constructor Description EncryptionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetDigitalSignatureType(java.security.Key signingKey)Returns the type of digital signature used with the specified signing key.static java.math.BigIntegergetRandomBigInteger(int bits)Creates a random BigInteger greater than 0 with the specified number of bits.static java.lang.StringgetSignatureAlgorithm(java.lang.String messageDigest, java.security.Key signingKey)Creates a signature algorithm string using the specified message digest and the encryption type corresponding to the supplied signingKey.static booleanisEcKey(java.security.Key key)Returns true if the key is an elliptic curve public or private key.static booleanisRsaKey(java.security.Key key)Returns true if the key is an RSA public or private key.static booleanisUnlimitedStrengthAllowed()Determines if unlimited-strength cryptography is allowed, i.e.static java.lang.StringreadPemStringFromFile(java.io.File file)Convenience method to read PEM data from a file.static voidwritePemStringToFile(java.io.File file, java.lang.String pemDataToWrite)Convenience method to write PEM data to a file.
-
-
-
Method Detail
-
getSignatureAlgorithm
public static java.lang.String getSignatureAlgorithm(java.lang.String messageDigest, java.security.Key signingKey)Creates a signature algorithm string using the specified message digest and the encryption type corresponding to the supplied signingKey. Useful when generating the signature algorithm to be used to sign server certificates using the CA root certificate's signingKey.For example, if the root certificate has an RSA private key, and you wish to use the SHA256 message digest, this method will return the string "SHA256withRSA". See the "Signature Algorithms" section of http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html for a list of JSSE-supported signature algorithms.
- Parameters:
messageDigest- digest to use to sign the certificate, such as SHA512signingKey- private key that will be used to sign the certificate- Returns:
- a JCA-compatible signature algorithm
-
getDigitalSignatureType
public static java.lang.String getDigitalSignatureType(java.security.Key signingKey)
Returns the type of digital signature used with the specified signing key.- Parameters:
signingKey- private key that will be used to sign a certificate (or something else)- Returns:
- a string representing the digital signature type (ECDSA, RSA, etc.)
-
getRandomBigInteger
public static java.math.BigInteger getRandomBigInteger(int bits)
Creates a random BigInteger greater than 0 with the specified number of bits.- Parameters:
bits- number of bits to generate- Returns:
- random BigInteger
-
isRsaKey
public static boolean isRsaKey(java.security.Key key)
Returns true if the key is an RSA public or private key.- Parameters:
key- key- Returns:
- isRsaKey
-
isEcKey
public static boolean isEcKey(java.security.Key key)
Returns true if the key is an elliptic curve public or private key.- Parameters:
key- key- Returns:
- isEcKey
-
writePemStringToFile
public static void writePemStringToFile(java.io.File file, java.lang.String pemDataToWrite)Convenience method to write PEM data to a file. The file will be encoded in the US_ASCII character set.- Parameters:
file- file to write topemDataToWrite- PEM data to write to the file
-
readPemStringFromFile
public static java.lang.String readPemStringFromFile(java.io.File file)
Convenience method to read PEM data from a file. The file encoding must be US_ASCII.- Parameters:
file- file to read from- Returns:
- PEM data from file
-
isUnlimitedStrengthAllowed
public static boolean isUnlimitedStrengthAllowed()
Determines if unlimited-strength cryptography is allowed, i.e. if this JRE has then the unlimited strength policy files installed.- Returns:
- true if unlimited strength cryptography is allowed, otherwise false
-
-