Class KeyImports
One exact PEM block is accepted, with canonical padded Base64 and matching labels. Public DER is SPKI. Private material is unencrypted PKCS#8 version 0 without attributes/outer public fields, or two-prime RSA PKCS#1 version 0. SEC1 armor, encrypted keys, RFC5958 version 1/attributes, P-521, Ed448, XDH and RSA-PSS containers are outside this profile. EC's inner named parameters must agree with its outer parameters; an embedded public hint must be a well-formed on-curve point but remains untrusted metadata. Import does not establish scalar-to-hint or key-pair agreement; use the separate explicit pair check.
Certificate parsing checks the embedded key profile, not certificate signatures, trust, chains, hostname, time, revocation or complete inner DER canonicality. Caller input remains unchanged. Owned private DER and pair-check challenge/signature buffers are erased; provider-owned keys, copies and immutable values remain under JCA/provider ownership. No method exports private key material or implicitly signs during import.
- Since:
- 1.0.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull X509CertificatecertificateFromDer(byte @NonNull [] der) Imports one DER certificate and checks its embedded key profile, without establishing certificate trust.static @NonNull X509CertificateImports one CERTIFICATE PEM block and checks its embedded key profile, without establishing certificate trust.static voidcheckKeyPair(@NonNull PrivateKey privateKey, @NonNull PublicKey publicKey, @NonNull Duration remainingBudget) Checks agreement with a fresh 32-byte noncredential challenge, a fresh JCA signer and the independent verifier.static @NonNull PrivateKeyImports one PRIVATE KEY or RSA PRIVATE KEY PEM block in the selected unencrypted private-container profile.static @NonNull PrivateKeyprivateKeyFromPkcs8Der(byte @NonNull [] der) Imports one unencrypted PKCS#8 version 0 key without attributes or an outer public-key field.Imports one PUBLIC KEY PEM block under the selected public-key profile.publicKeyFromSpkiDer(byte @NonNull [] der) Imports one canonical SubjectPublicKeyInfo DER value under the selected public-key profile.static @NonNull PrivateKeyrsaPrivateKeyFromPkcs1Der(byte @NonNull [] der) Imports one two-prime RSA PKCS#1 version 0 private key.
-
Method Details
-
certificateFromPem
Imports one CERTIFICATE PEM block and checks its embedded key profile, without establishing certificate trust.- Parameters:
pem- at most 98304 characters- Returns:
- the caller-owned parsed certificate
- Throws:
NullPointerException- if pem is nullKeyImportException- if parsing, size or the selected key profile fails- Since:
- 1.0.0
-
certificateFromDer
Imports one DER certificate and checks its embedded key profile, without establishing certificate trust.- Parameters:
der- at most 65536 bytes; not modified- Returns:
- the caller-owned parsed certificate
- Throws:
NullPointerException- if der is nullKeyImportException- if parsing, size or the selected key profile fails- Since:
- 1.0.0
-
publicKeyFromPem
Imports one PUBLIC KEY PEM block under the selected public-key profile.- Parameters:
pem- at most 98304 characters- Returns:
- the caller-owned checked JCA key
- Throws:
NullPointerException- if pem is nullKeyImportException- if parsing, size or the selected key profile fails- Since:
- 1.0.0
-
publicKeyFromSpkiDer
Imports one canonical SubjectPublicKeyInfo DER value under the selected public-key profile.- Parameters:
der- at most 65536 bytes; not modified- Returns:
- the caller-owned checked JCA key
- Throws:
NullPointerException- if der is nullKeyImportException- if parsing, size or the selected key profile fails- Since:
- 1.0.0
-
privateKeyFromPem
Imports one PRIVATE KEY or RSA PRIVATE KEY PEM block in the selected unencrypted private-container profile.- Parameters:
pem- at most 98304 characters- Returns:
- the caller-owned decoded JCA key; pair agreement is not established
- Throws:
NullPointerException- if pem is nullKeyImportException- if parsing, size or the selected key profile fails- Since:
- 1.0.0
-
privateKeyFromPkcs8Der
Imports one unencrypted PKCS#8 version 0 key without attributes or an outer public-key field.- Parameters:
der- at most 65536 bytes; not modified- Returns:
- the caller-owned decoded JCA key; pair agreement is not established
- Throws:
NullPointerException- if der is nullKeyImportException- if parsing, size or the selected key profile fails- Since:
- 1.0.0
-
rsaPrivateKeyFromPkcs1Der
Imports one two-prime RSA PKCS#1 version 0 private key.- Parameters:
der- at most 65536 bytes; not modified- Returns:
- the caller-owned decoded RSA key; pair agreement is not established
- Throws:
NullPointerException- if der is nullKeyImportException- if parsing, size or the selected key profile fails- Since:
- 1.0.0
-
checkKeyPair
public static void checkKeyPair(@NonNull PrivateKey privateKey, @NonNull PublicKey publicKey, @NonNull Duration remainingBudget) Checks agreement with a fresh 32-byte noncredential challenge, a fresh JCA signer and the independent verifier. The public key must provide a bounded canonical SPKI encoding; it is reparsed to a checked stable projection. The private key may remain opaque; its encoding is never requested. No signature or challenge is returned. One original monotonic budget covers public snapshot, provider/random initialization, signing and verification. Trusted synchronous providers must cooperate; these checks cannot preempt a blocked provider. No retry occurs.- Parameters:
privateKey- the caller-owned private keypublicKey- the caller-owned encodable public keyremainingBudget- the original remaining budget; nonpositive values are exhausted- Throws:
NullPointerException- if a required argument is nullKeyImportException- if the profile, pair, provider, interruption or budget check fails- Since:
- 1.0.0
-