Package com.google.crypto.tink.subtle
Class SubtleUtil
- java.lang.Object
-
- com.google.crypto.tink.subtle.SubtleUtil
-
public final class SubtleUtil extends java.lang.ObjectHelper methods.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intandroidApiLevel()Deprecated.Please reimplement this method in your code instead.static java.math.BigIntegerbytes2Integer(byte[] bs)Converts an unsigned, big-endian encoded byte array to a non-negative integer (https://tools.ietf.org/html/rfc8017#section-4.1).static byte[]integer2Bytes(java.math.BigInteger num, int intendedLength)Converts a nonnegative integer to a byte array of a specified length (https://tools.ietf.org/html/rfc8017#section-4.2).static booleanisAndroid()Best-effort checks that this is Android.static byte[]mgf1(byte[] mgfSeed, int maskLen, Enums.HashType mgfHash)Computes MGF1 as defined at https://tools.ietf.org/html/rfc8017#appendix-B.2.1.static voidputAsUnsigedInt(java.nio.ByteBuffer buffer, long value)Insertsvalueas unsigned into intobuffer.static java.lang.StringtoDigestAlgo(Enums.HashType hash)Returns the digest algorithm name corresponding to a hash type.static java.lang.StringtoEcdsaAlgo(Enums.HashType hash)Returns the Ecdsa algorithm name corresponding to a hash type.static java.lang.StringtoRsaSsaPkcs1Algo(Enums.HashType hash)Returns the RSA SSA (Signature with Appendix) PKCS1 algorithm name corresponding to a hash type.
-
-
-
Method Detail
-
toEcdsaAlgo
public static java.lang.String toEcdsaAlgo(Enums.HashType hash) throws java.security.GeneralSecurityException
Returns the Ecdsa algorithm name corresponding to a hash type.- Parameters:
hash- the hash type- Returns:
- the JCE's Ecdsa algorithm name for the hash.
- Throws:
java.security.GeneralSecurityException- ifhashis not supported or is not safe for digital signature.
-
toRsaSsaPkcs1Algo
public static java.lang.String toRsaSsaPkcs1Algo(Enums.HashType hash) throws java.security.GeneralSecurityException
Returns the RSA SSA (Signature with Appendix) PKCS1 algorithm name corresponding to a hash type.- Parameters:
hash- the hash type.- Returns:
- the JCE's RSA SSA PKCS1 algorithm name for the hash.
- Throws:
java.security.GeneralSecurityException- ifhashis not supported or is not safe for digital signature.
-
toDigestAlgo
public static java.lang.String toDigestAlgo(Enums.HashType hash) throws java.security.GeneralSecurityException
Returns the digest algorithm name corresponding to a hash type.- Parameters:
hash- the hash type.- Returns:
- theh JCE's hash algorithm name.
- Throws:
java.security.GeneralSecurityException- ifhashis not supported.
-
isAndroid
public static boolean isAndroid()
Best-effort checks that this is Android.- Returns:
- true if running on Android.
-
androidApiLevel
@Deprecated public static int androidApiLevel()
Deprecated.Please reimplement this method in your code instead. From within Tink, useUtil.getAndroidApiLeveldirectly.Returns the Android API level or -1 if Tink isn't running on Android.
-
bytes2Integer
public static java.math.BigInteger bytes2Integer(byte[] bs)
Converts an unsigned, big-endian encoded byte array to a non-negative integer (https://tools.ietf.org/html/rfc8017#section-4.1).- Parameters:
bs- the byte array to be converted to integer.- Returns:
- the corresponding integer.
-
integer2Bytes
public static byte[] integer2Bytes(java.math.BigInteger num, int intendedLength) throws java.security.GeneralSecurityExceptionConverts a nonnegative integer to a byte array of a specified length (https://tools.ietf.org/html/rfc8017#section-4.2).- Parameters:
num- nonnegative integer to be converted.intendedLength- intended length of the resulting integer.- Returns:
- the corresponding byte array of length
intendedLength. - Throws:
java.security.GeneralSecurityException
-
mgf1
public static byte[] mgf1(byte[] mgfSeed, int maskLen, Enums.HashType mgfHash) throws java.security.GeneralSecurityExceptionComputes MGF1 as defined at https://tools.ietf.org/html/rfc8017#appendix-B.2.1.- Throws:
java.security.GeneralSecurityException
-
putAsUnsigedInt
public static void putAsUnsigedInt(java.nio.ByteBuffer buffer, long value) throws java.security.GeneralSecurityExceptionInsertsvalueas unsigned into intobuffer.@throws GeneralSecurityException if not 0 <= value < 2^32.
- Throws:
java.security.GeneralSecurityException
-
-