Package com.iizix.push.vapid
Class Utils
- java.lang.Object
- com.iizix.push.vapid.Utils
public class Utils extends java.lang.Object
Constructor Summary
Constructors Constructor Description Utils()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcombinedLength(byte[]... arrays)Compute combined array lengthstatic byte[]concat(byte[]... arrays)Utility to concat byte arraysstatic byte[]encode(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey)static byte[]encode(org.bouncycastle.jce.interfaces.ECPublicKey publicKey)Get the uncompressed encoding of the public key point.static java.security.PrivateKeyloadPrivateKey(byte[] decodedPrivateKey)Load the private key from a byte arraystatic java.security.PrivateKeyloadPrivateKey(java.lang.String encodedPrivateKey)Load the private key from a URL-safe base64 encoded stringstatic java.security.PublicKeyloadPublicKey(byte[] decodedPublicKey)Load the public key from a byte array.static java.security.PublicKeyloadPublicKey(java.lang.String encodedPublicKey)Load the public key from a URL-safe base64 encoded string.static org.bouncycastle.jce.interfaces.ECPublicKeyloadPublicKey(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey)Load a public key from the private key.static byte[]toByteArray(int integer, int size)Create a byte array of the given length from the given integer.static booleanverifyKeyPair(java.security.PrivateKey privateKey, java.security.PublicKey publicKey)Verify that the private key belongs to the public key.
Field Detail
CURVE
public static final java.lang.String CURVE
- See Also:
- Constant Field Values
ALGORITHM
public static final java.lang.String ALGORITHM
- See Also:
- Constant Field Values
Method Detail
encode
public static byte[] encode(org.bouncycastle.jce.interfaces.ECPublicKey publicKey)
Get the uncompressed encoding of the public key point. The resulting array should be 65 bytes length and start with 0x04 followed by the x and y coordinates (32 bytes each).- Parameters:
publicKey-- Returns:
encode
public static byte[] encode(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey)
loadPublicKey
public static java.security.PublicKey loadPublicKey(java.lang.String encodedPublicKey) throws java.security.NoSuchProviderException, java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecExceptionLoad the public key from a URL-safe base64 encoded string. Takes into account the different encodings, including point compression.- Parameters:
encodedPublicKey-- Throws:
java.security.NoSuchProviderExceptionjava.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecException
loadPublicKey
public static java.security.PublicKey loadPublicKey(byte[] decodedPublicKey) throws java.security.NoSuchProviderException, java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecExceptionLoad the public key from a byte array.- Parameters:
decodedPublicKey-- Throws:
java.security.NoSuchProviderExceptionjava.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecException
loadPrivateKey
public static java.security.PrivateKey loadPrivateKey(java.lang.String encodedPrivateKey) throws java.security.NoSuchProviderException, java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecExceptionLoad the private key from a URL-safe base64 encoded string- Parameters:
encodedPrivateKey-- Returns:
- Throws:
java.security.NoSuchProviderExceptionjava.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecException
loadPrivateKey
public static java.security.PrivateKey loadPrivateKey(byte[] decodedPrivateKey) throws java.security.NoSuchProviderException, java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecExceptionLoad the private key from a byte array- Parameters:
decodedPrivateKey-- Returns:
- Throws:
java.security.NoSuchProviderExceptionjava.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecException
loadPublicKey
public static org.bouncycastle.jce.interfaces.ECPublicKey loadPublicKey(org.bouncycastle.jce.interfaces.ECPrivateKey privateKey) throws java.security.NoSuchProviderException, java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecExceptionLoad a public key from the private key.- Parameters:
privateKey-- Returns:
- Throws:
java.security.NoSuchProviderExceptionjava.security.NoSuchAlgorithmExceptionjava.security.spec.InvalidKeySpecException
verifyKeyPair
public static boolean verifyKeyPair(java.security.PrivateKey privateKey, java.security.PublicKey publicKey)Verify that the private key belongs to the public key.- Parameters:
privateKey-publicKey-- Returns:
concat
public static byte[] concat(byte[]... arrays)
Utility to concat byte arrays
combinedLength
public static int combinedLength(byte[]... arrays)
Compute combined array length
toByteArray
public static byte[] toByteArray(int integer, int size)Create a byte array of the given length from the given integer.- Parameters:
integer-size-- Returns: