Package com.iizix.push.vapid
Class Utils
java.lang.Object
com.iizix.push.vapid.Utils
Field Summary
FieldsConstructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic intcombinedLength(byte[]... arrays) Compute combined array lengthstatic byte[]concat(byte[]... arrays) Utility to concat byte arraysstatic byte[]encode(ECPrivateKey privateKey) static byte[]encode(ECPublicKey publicKey) Get the uncompressed encoding of the public key point.static PrivateKeyloadPrivateKey(byte[] decodedPrivateKey) Load the private key from a byte arraystatic PrivateKeyloadPrivateKey(String encodedPrivateKey) Load the private key from a URL-safe base64 encoded stringstatic PublicKeyloadPublicKey(byte[] decodedPublicKey) Load the public key from a byte array.static PublicKeyloadPublicKey(String encodedPublicKey) Load the public key from a URL-safe base64 encoded string.static ECPublicKeyloadPublicKey(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(PrivateKey privateKey, PublicKey publicKey) Verify that the private key belongs to the public key.
Field Details
CURVE
- See Also:
ALGORITHM
- See Also:
Constructor Details
Utils
public Utils()
Method Details
encode
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
loadPublicKey
public static PublicKey loadPublicKey(String encodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException Load the public key from a URL-safe base64 encoded string. Takes into account the different encodings, including point compression.- Parameters:
encodedPublicKey-- Throws:
NoSuchProviderExceptionNoSuchAlgorithmExceptionInvalidKeySpecException
loadPublicKey
public static PublicKey loadPublicKey(byte[] decodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException Load the public key from a byte array.- Parameters:
decodedPublicKey-- Throws:
NoSuchProviderExceptionNoSuchAlgorithmExceptionInvalidKeySpecException
loadPrivateKey
public static PrivateKey loadPrivateKey(String encodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException Load the private key from a URL-safe base64 encoded string- Parameters:
encodedPrivateKey-- Returns:
- Throws:
NoSuchProviderExceptionNoSuchAlgorithmExceptionInvalidKeySpecException
loadPrivateKey
public static PrivateKey loadPrivateKey(byte[] decodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException Load the private key from a byte array- Parameters:
decodedPrivateKey-- Returns:
- Throws:
NoSuchProviderExceptionNoSuchAlgorithmExceptionInvalidKeySpecException
loadPublicKey
public static ECPublicKey loadPublicKey(ECPrivateKey privateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException Load a public key from the private key.- Parameters:
privateKey-- Returns:
- Throws:
NoSuchProviderExceptionNoSuchAlgorithmExceptionInvalidKeySpecException
verifyKeyPair
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 arrayscombinedLength
public static int combinedLength(byte[]... arrays) Compute combined array lengthtoByteArray
public static byte[] toByteArray(int integer, int size) Create a byte array of the given length from the given integer.- Parameters:
integer-size-- Returns: