Class SignatureOperations
Public facade for digital signature operations.
All methods are exposed via AuthenticatedSdk.
- Since:
- 3.0.0
- Author:
- ANKATech Solutions Inc.
-
Constructor Summary
ConstructorsConstructorDescriptionSignatureOperations(InternalServiceFactory svc, co.ankatech.ankasecure.openapi.client.AnkaSecureOpenApiClient openApiClient, org.slf4j.Logger userLogger) -
Method Summary
Modifier and TypeMethodDescriptionSigns raw bytes using the key identified bykid.sign(String kid, byte[] data, JwsSerialization serialization) Signs raw bytes with an explicit JWS serialization selection (PRD §60).signFileCompact(String kid, Path input, Path output) Signs a file using the key identified bykid.signFileCompact(String kid, Path input, Path output, JwsSerialization serialization) Signs a file with an explicit JWS serialization selection (PRD §60).signFileStream(String kid, Path input, Path output) Signs a file in streaming mode (designed for large files >100 MB).verifySignature(String jws) Verifies a compact JWS signature string.verifySignatureFile(Path jwsFile) Verifies a JWS signature from a file (compact or JWS-JSON).verifySignatureStream(Path dataFile, Path signatureFile) Verifies a detached signature in streaming mode (designed for large files >100 MB).verifySignatureUtilityStream(String kty, String alg, String publicKeyB64, String signatureB64, Path dataFile) Verifies a signature using an external public key (utility operation).
-
Constructor Details
-
SignatureOperations
public SignatureOperations(InternalServiceFactory svc, co.ankatech.ankasecure.openapi.client.AnkaSecureOpenApiClient openApiClient, org.slf4j.Logger userLogger)
-
-
Method Details
-
sign
Signs raw bytes using the key identified bykid.Computes a digital signature over the provided data using the signing key's algorithm (ML-DSA, SLH-DSA, ECDSA, RSA-PSS, etc.). The result is a compact JWS (RFC 7515) string containing the signature and metadata needed for verification.
This method is suitable for in-memory payloads up to ~100 MB. For larger files, use
signFileStream(String, Path, Path)to avoid loading the entire payload into memory.- Parameters:
kid- key identifier referencing a signing key stored in ANKASecure©; must not benulldata- the raw bytes to sign; must not benull- Returns:
- signature result containing the JWS token and operation metadata;
never
null - Throws:
AnkaSecureSdkException- if the key identified bykiddoes not exist, does not support signing, the authenticated client lacks permission, or the server returns an errorNullPointerException- ifkidordataisnull- Since:
- 3.0.0
-
sign
public SignResult sign(String kid, byte[] data, JwsSerialization serialization) throws AnkaSecureSdkException Signs raw bytes with an explicit JWS serialization selection (PRD §60).Ergonomic overload of
sign(String, byte[]). PassingJwsSerialization.COMPACTorJwsSerialization.JSONrequests that representation; anullserializationis equivalent to callingsign(String, byte[])(the server chooses).- Parameters:
kid- key identifier referencing a signing key; must not benulldata- the raw bytes to sign; must not benullserialization- requested serialization, ornullto let the server choose- Returns:
- signature result; never
null - Throws:
AnkaSecureSdkException- on error, including HTTP 400 when COMPACT is requested but the deployment mandates a qualified timestampNullPointerException- ifkidordataisnull- Since:
- 3.0.0
-
signFileCompact
public SignResult signFileCompact(String kid, Path input, Path output) throws AnkaSecureSdkException Signs a file using the key identified bykid.The entire file is loaded into memory, signed, and the resulting compact JWS (RFC 7515) is written to the output file. This method is suitable for files up to ~100 MB. For larger files, use
signFileStream(String, Path, Path)which processes files in chunks without loading them entirely into memory.The output file contains a complete compact JWS string that can be verified using
verifySignature(Path).- Parameters:
kid- key identifier referencing a signing key stored in ANKASecure©; must not benullinput- path to file to sign; must not benulland file must existoutput- path where JWS will be written; must not benull- Returns:
- signature result containing the JWS token and operation metadata;
never
null - Throws:
AnkaSecureSdkException- if the key identified bykiddoes not exist, does not support signing, the input file cannot be read, the output file cannot be written, or the server returns an errorNullPointerException- ifkid,input, oroutputisnull- Since:
- 3.0.0
-
signFileCompact
public SignResult signFileCompact(String kid, Path input, Path output, JwsSerialization serialization) throws AnkaSecureSdkException Signs a file with an explicit JWS serialization selection (PRD §60).Ergonomic overload of
signFileCompact(String, Path, Path). Anullserializationdefers to the server. When the server mandates a qualified timestamp, the written output is a JWS-JSON artifact carrying the JAdESsigTst(never collapsed to a compact string).- Parameters:
kid- key identifier for signing; must not benullinput- input file (max 5MB); must not benulloutput- output file; must not benullserialization- requested serialization, ornullto let the server choose- Returns:
- signature result; never
null - Throws:
AnkaSecureSdkException- on error, including HTTP 400 when COMPACT is requested but the deployment mandates a qualified timestampNullPointerException- ifkid,input, oroutputisnull- Since:
- 3.0.0
-
signFileStream
Signs a file in streaming mode (designed for large files >100 MB).Streaming variant that processes the file in chunks using multipart upload, minimizing memory consumption. Unlike
signFile(String, Path, Path), this method produces a detached JWS (General-JSON header + separate signature) instead of a compact JWS string.The detached format separates the JWS header from the signed payload, enabling efficient streaming verification of large files using
verifySignatureStream(Path, Path).- Parameters:
kid- key identifier referencing a signing key stored in ANKASecure©; must not benullinput- path to file to sign; must not benulland file must existoutput- path where detached signature will be written; must not benull- Returns:
- signature result with operation metadata (JWS token field may be
nullin streaming mode); nevernull - Throws:
AnkaSecureSdkException- if the key identified bykiddoes not exist, does not support signing, the input file cannot be read, the output file cannot be written, or the server returns an errorNullPointerException- ifkid,input, oroutputisnull- Since:
- 3.0.0
-
verifySignatureFile
Verifies a JWS signature from a file (compact or JWS-JSON).Reads a JWS token from the file — either an RFC 7515 §7.1 compact string or an RFC 7515 §7.2 JWS-JSON object (which MAY carry a JAdES qualified timestamp) — extracts the signing key identifier, retrieves the public key, and verifies the signature. This method is the inverse of the attached
signFileCompact(String, Path, Path).The verification checks both the cryptographic signature and the key's current status (revoked, expired, usage limits). A signature is only considered valid if both checks pass. Any embedded qualified timestamp is surfaced informationally via
VerifySignatureResult.getQualifiedTimestamp()and NEVER affectsvalid.- Parameters:
jwsFile- path to file containing a compact or JWS-JSON token; must not benulland file must exist- Returns:
- verification result with validity flag, key used, algorithm, warnings,
and optional qualified timestamp; never
null - Throws:
AnkaSecureSdkException- if the file cannot be read, the JWS is malformed, the signing key does not exist, or the server returns an errorNullPointerException- ifjwsFileisnull- Since:
- 3.0.0
-
verifySignature
Verifies a compact JWS signature string.Extracts the signing key identifier from the JWS header, retrieves the public key, and verifies the signature. This method is the inverse of
sign(String, byte[]). The JWS token must be a valid compact JWS (RFC 7515) as produced by ANKASecure© signing operations.The verification checks both the cryptographic signature and the key's current status (revoked, expired, usage limits). A signature is only considered valid if both checks pass.
- Parameters:
jws- the compact JWS token string (three Base64URL segments separated by dots); must not benull- Returns:
- verification result with validity flag, key used, algorithm, and warnings;
never
null - Throws:
AnkaSecureSdkException- if the JWS is malformed, the signing key does not exist, or the server returns an errorNullPointerException- ifjwsisnull- Since:
- 3.0.0
-
verifySignatureStream
public VerifySignatureResult verifySignatureStream(Path dataFile, Path signatureFile) throws AnkaSecureSdkException Verifies a detached signature in streaming mode (designed for large files >100 MB).Streaming variant that verifies signatures on large files without loading them entirely into memory. This method is the inverse of
signFileStream(String, Path, Path)and expects a detached JWS format where the signature is stored separately from the signed data.The verification checks both the cryptographic signature and the key's current status. The data file is read in chunks and verified against the detached signature.
- Parameters:
dataFile- path to original data file; must not benulland file must existsignatureFile- path to detached signature file; must not benulland file must exist- Returns:
- verification result with validity flag, key used, algorithm, and warnings;
never
null - Throws:
AnkaSecureSdkException- if either file cannot be read, the signature is malformed, the signing key does not exist, or the server returns an errorNullPointerException- ifdataFileorsignatureFileisnull- Since:
- 3.0.0
-
verifySignatureUtilityStream
public VerifySignatureResult verifySignatureUtilityStream(String kty, String alg, String publicKeyB64, String signatureB64, Path dataFile) throws AnkaSecureSdkException Verifies a signature using an external public key (utility operation).Server-side signature verification using a public key provided by the client rather than retrieved from the key store. This utility operation enables verification of signatures created outside ANKASecure© or verification before key import.
The signature and data are processed in streaming mode, making this suitable for verifying large files without memory constraints.
- Parameters:
kty- key type; one of "RSA", "EC", "ML-DSA", "SLH-DSA"; must not benullalg- algorithm identifier (e.g., "RS256", "ES256", "ML-DSA-87", "SLH-DSA-128s"); must not benullpublicKeyB64- Base64-encoded public key material; must not benullsignatureB64- Base64-encoded signature bytes; must not benulldataFile- path to original data file; must not benulland file must exist- Returns:
- verification result with validity flag and algorithm used; never
null - Throws:
AnkaSecureSdkException- if the key type/algorithm combination is unsupported, the public key or signature is malformed, the data file cannot be read, or the server returns an errorNullPointerException- if any parameter isnull- Since:
- 3.0.0
-