Class P256Keys
java.base only: the raw forms the wire carries - the 65-byte uncompressed point 0x04 || X || Y of a public key and the 32-byte scalar of a private key, both base64url without padding - to and from the JDK's own ECPublicKey and ECPrivateKey.No provider is named, deliberately. The former loaders in com.iizix.push.vapid.Utils hand BouncyCastle key specs to a KeyFactory obtained from the "BC" provider by name. Under Equinox the spec class from the com.iizix.core bundle and the provider's own copy come from different class loaders, and the factory answers "key spec not recognized" - measured in the Designer on 2026-09-08 with a key pair that is correct. The Designer's debug server is where the Push Notification acceptance test runs, so the transports cannot depend on that path. java.security.interfaces and java.security.spec live in java.base, one loader for the whole VM, and SunEC supplies EC key generation, ECDSA and ECDH there. This is the same reasoning VAPIDKeys.generateKeys() records for the generator.
Thread-safe: no state.
- Author:
- Christopher Mindus
Field Summary
FieldsMethod Summary
Modifier and TypeMethodDescriptionstatic byte[]Encodes a public key as the uncompressed point, each coordinate fixed at 32 bytes so a coordinate with leading zero bytes never encodes shorter.static KeyPairgenerateKeyPair(SecureRandom random) Generates a P-256 key pair.static ECPrivateKeyloadPrivateKey(byte[] scalar) Loads a private key from its raw scalar.static ECPrivateKeyloadPrivateKey(String base64url) Loads a private key from its base64url form, theVPrivKeyof an application.static ECPublicKeyloadPublicKey(byte[] point) Loads a public key from its raw uncompressed point.static ECPublicKeyloadPublicKey(String base64url) Loads a public key from its base64url form, theVPubKeyof an application or thep256dhof a browser subscription.static ECParameterSpecp256()Gets the P-256 domain parameters from the JDK.
Field Details
CURVE
The curve name the JDK knows P-256 by. secp256r1 is prime256v1 is NIST P-256.- See Also:
Method Details
p256
Gets the P-256 domain parameters from the JDK.- Returns:
- The parameters.
- Throws:
GeneralSecurityException- If the JDK has no EC support, which cannot happen on a supported JVM.
loadPrivateKey
Loads a private key from its raw scalar.- Parameters:
scalar- The unsigned big-endian scalar,VAPIDKeys.PRIVATE_KEY_LENGTHbytes.- Returns:
- The key.
- Throws:
IllegalArgumentException- If the scalar has the wrong length.GeneralSecurityException- If the scalar is not a valid private key.
loadPrivateKey
Loads a private key from its base64url form, theVPrivKeyof an application.- Parameters:
base64url- The scalar, base64url with or without padding.- Returns:
- The key.
- Throws:
IllegalArgumentException- If the text is not base64url or the scalar has the wrong length.GeneralSecurityException- If the scalar is not a valid private key.
loadPublicKey
Loads a public key from its raw uncompressed point.- Parameters:
point- The point0x04 || X || Y,VAPIDKeys.PUBLIC_KEY_LENGTHbytes.- Returns:
- The key.
- Throws:
IllegalArgumentException- If the point has the wrong length or is not uncompressed.GeneralSecurityException- If the point is not on the curve.
loadPublicKey
Loads a public key from its base64url form, theVPubKeyof an application or thep256dhof a browser subscription.- Parameters:
base64url- The point, base64url with or without padding.- Returns:
- The key.
- Throws:
IllegalArgumentException- If the text is not base64url or the point is malformed.GeneralSecurityException- If the point is not on the curve.
encodePublicKey
Encodes a public key as the uncompressed point, each coordinate fixed at 32 bytes so a coordinate with leading zero bytes never encodes shorter.- Parameters:
key- The key.- Returns:
0x04 || X || Y,VAPIDKeys.PUBLIC_KEY_LENGTHbytes.
generateKeyPair
Generates a P-256 key pair.- Parameters:
random- The random source, null for the JDK default.- Returns:
- The pair, JDK keys.
- Throws:
GeneralSecurityException- If the JDK cannot generate it.