Package com.iizix.push.vapid
Class Utils
java.lang.Object
com.iizix.push.vapid.Utils
Field Summary
Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionstatic int
combinedLength
(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 PrivateKey
loadPrivateKey
(byte[] decodedPrivateKey) Load the private key from a byte arraystatic PrivateKey
loadPrivateKey
(String encodedPrivateKey) Load the private key from a URL-safe base64 encoded stringstatic PublicKey
loadPublicKey
(byte[] decodedPublicKey) Load the public key from a byte array.static PublicKey
loadPublicKey
(String encodedPublicKey) Load the public key from a URL-safe base64 encoded string.static ECPublicKey
loadPublicKey
(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 boolean
verifyKeyPair
(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:
NoSuchProviderException
NoSuchAlgorithmException
InvalidKeySpecException
loadPublicKey
public static PublicKey loadPublicKey(byte[] decodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException Load the public key from a byte array.- Parameters:
decodedPublicKey
-- Throws:
NoSuchProviderException
NoSuchAlgorithmException
InvalidKeySpecException
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:
NoSuchProviderException
NoSuchAlgorithmException
InvalidKeySpecException
loadPrivateKey
public static PrivateKey loadPrivateKey(byte[] decodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException Load the private key from a byte array- Parameters:
decodedPrivateKey
-- Returns:
- Throws:
NoSuchProviderException
NoSuchAlgorithmException
InvalidKeySpecException
loadPublicKey
public static ECPublicKey loadPublicKey(ECPrivateKey privateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException Load a public key from the private key.- Parameters:
privateKey
-- Returns:
- Throws:
NoSuchProviderException
NoSuchAlgorithmException
InvalidKeySpecException
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: