Package com.google.crypto.tink.subtle
Class Validators
- java.lang.Object
-
- com.google.crypto.tink.subtle.Validators
-
public final class Validators extends java.lang.ObjectValidation helper methods.- Since:
- 1.0.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidvalidateAesKeySize(int sizeInBytes)static voidvalidateCryptoKeyUri(java.lang.String kmsKeyUri)static voidvalidateExists(java.io.File f)static java.lang.StringvalidateKmsKeyUriAndRemovePrefix(java.lang.String expectedPrefix, java.lang.String kmsKeyUri)Validates thatkmsKeyUristarts withexpectedPrefix, and removes the prefix.static voidvalidateNotExists(java.io.File f)static voidvalidateRsaModulusSize(int modulusSize)Validates whethermodulusSizeis at least 2048-bit.static voidvalidateRsaPublicExponent(java.math.BigInteger publicExponent)Validates whetherpublicExponentis odd and greater than 65536.static voidvalidateSignatureHash(Enums.HashType hash)Validates whetherhashis safe to use for digital signature.static voidvalidateTypeUrl(java.lang.String typeUrl)static voidvalidateVersion(int candidate, int maxExpected)
-
-
-
Method Detail
-
validateTypeUrl
public static void validateTypeUrl(java.lang.String typeUrl) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException- iftypeUrlis in invalid format.
-
validateAesKeySize
public static void validateAesKeySize(int sizeInBytes) throws java.security.InvalidAlgorithmParameterException- Throws:
java.security.InvalidAlgorithmParameterException- ifsizeInBytesis not supported.
-
validateVersion
public static void validateVersion(int candidate, int maxExpected) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException- ifcandidateis negative or larger thanmaxExpected.
-
validateSignatureHash
public static void validateSignatureHash(Enums.HashType hash) throws java.security.GeneralSecurityException
Validates whetherhashis safe to use for digital signature.- Throws:
java.security.GeneralSecurityException- ifhashis invalid or is not safe to use for digital signature.
-
validateRsaModulusSize
public static void validateRsaModulusSize(int modulusSize) throws java.security.GeneralSecurityExceptionValidates whethermodulusSizeis at least 2048-bit.To reach 128-bit security strength, RSA's modulus must be at least 3072-bit while 2048-bit RSA key only has 112-bit security. Nevertheless, a 2048-bit RSA key is considered safe by NIST until 2030 (see https://www.keylength.com/en/4/).
- Throws:
java.security.GeneralSecurityException- ifmodulusSizeis less than 2048-bit or if the modulus violates FIPS restrictions if they have been enabled.
-
validateRsaPublicExponent
public static void validateRsaPublicExponent(java.math.BigInteger publicExponent) throws java.security.GeneralSecurityExceptionValidates whetherpublicExponentis odd and greater than 65536.The primes p and q are chosen such that (p-1)(q-1) is relatively prime to the public exponent. Therefore, the public exponent must be odd. Furthermore, choosing a public exponent which is not greater than 65536 can lead to weak instantiations of RSA. A public exponent which is odd and greater than 65536 conforms to the requirements set by NIST FIPS 186-4 (Appendix B.3.1).
- Throws:
java.security.GeneralSecurityException- ifpublicExponentis even or not greater than 65536.
-
validateNotExists
public static void validateNotExists(java.io.File f) throws java.io.IOException- Throws:
java.io.IOException- iffexists.
-
validateExists
public static void validateExists(java.io.File f) throws java.io.IOException- Throws:
java.io.IOException- iffdoes not exists.
-
validateKmsKeyUriAndRemovePrefix
public static java.lang.String validateKmsKeyUriAndRemovePrefix(java.lang.String expectedPrefix, java.lang.String kmsKeyUri)Validates thatkmsKeyUristarts withexpectedPrefix, and removes the prefix.- Throws:
java.lang.IllegalArgumentException- ifkmsKeyUriis invalid.
-
validateCryptoKeyUri
public static void validateCryptoKeyUri(java.lang.String kmsKeyUri) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException- ifkmsKeyUriis not a valid URI of a CryptoKey in Google Cloud KMS.
-
-