Class CryptoServiceImpl
- All Implemented Interfaces:
co.ankatech.ankasecure.sdk.internal.service.CryptoService
CryptoService.-
Nested Class Summary
Nested classes/interfaces inherited from interface co.ankatech.ankasecure.sdk.internal.service.CryptoService
co.ankatech.ankasecure.sdk.internal.service.CryptoService.DecryptBytesHolder -
Constructor Summary
ConstructorsConstructorDescriptionCryptoServiceImpl(co.ankatech.ankasecure.openapi.client.AnkaSecureOpenApiClient api) Convenience constructor using the defaultOverwritePolicy.FAIL_IF_EXISTSpolicy.CryptoServiceImpl(co.ankatech.ankasecure.openapi.client.AnkaSecureOpenApiClient api, OverwritePolicy overwritePolicy) -
Method Summary
Modifier and TypeMethodDescriptionco.ankatech.ankasecure.sdk.internal.service.CryptoService.DecryptBytesHolderdecryptBytes(String recipientKid, String jweToken) Decrypt a JWE (Compact or General JSON) that is already in RAM.decryptFile(String recipientKid, Path input, Path output) decryptFileStream(String recipientKid, Path input, Path output) Decrypts a JWET multipart file via streaming API.encryptBytes(String kid, byte[] plaintext) Encrypt raw bytes with a server-side **public** key.encryptFile(String kid, Path input, Path output) encryptFileStream(String kid, Path input, Path output) reencryptBytes(String newKid, String sourceKid, String jweToken) Re-encrypt a JWE in memory so it becomes protected bynewKid.reencryptFile(String newKid, String sourceKid, Path input, Path output) reencryptFileStream(String newKid, String sourceKid, Path input, Path output) Server-side re-encryption of a ciphertext with a new key.
-
Constructor Details
-
CryptoServiceImpl
public CryptoServiceImpl(co.ankatech.ankasecure.openapi.client.AnkaSecureOpenApiClient api) Convenience constructor using the defaultOverwritePolicy.FAIL_IF_EXISTSpolicy. -
CryptoServiceImpl
public CryptoServiceImpl(co.ankatech.ankasecure.openapi.client.AnkaSecureOpenApiClient api, OverwritePolicy overwritePolicy)
-
-
Method Details
-
encryptFile
- Specified by:
encryptFilein interfaceco.ankatech.ankasecure.sdk.internal.service.CryptoService- Throws:
AnkaSecureSdkException
-
decryptFile
public DecryptResultMetadata decryptFile(String recipientKid, Path input, Path output) throws AnkaSecureSdkException - Specified by:
decryptFilein interfaceco.ankatech.ankasecure.sdk.internal.service.CryptoService- Parameters:
recipientKid- the recipient to decrypt with, ornullwhen the JWE names one key- Throws:
AnkaSecureSdkException
-
reencryptFile
public ReencryptResult reencryptFile(String newKid, String sourceKid, Path input, Path output) throws AnkaSecureSdkException - Specified by:
reencryptFilein interfaceco.ankatech.ankasecure.sdk.internal.service.CryptoServicesourceKid- the recipient the re-encryption replaces, ornullwhen the JWE names one key- Throws:
AnkaSecureSdkException
-
encryptFileStream
public EncryptResult encryptFileStream(String kid, Path input, Path output) throws AnkaSecureSdkException - Specified by:
encryptFileStreamin interfaceco.ankatech.ankasecure.sdk.internal.service.CryptoService- Throws:
AnkaSecureSdkException
-
decryptFileStream
public DecryptResultMetadata decryptFileStream(String recipientKid, Path input, Path output) throws AnkaSecureSdkException Decrypts a JWET multipart file via streaming API.This implementation extracts the original JWET header JSON and forwards it as-is to the API without parsing, ensuring perfect forward compatibility with server-side fields unknown to this SDK version (e.g.,
anka_composite_mode, future extensions).Zero-overhead design: The header is treated as an opaque string that is simply forwarded to the server. No deserialization, no validation, no conditional logic based on key type.
- Specified by:
decryptFileStreamin interfaceco.ankatech.ankasecure.sdk.internal.service.CryptoService- Parameters:
recipientKid- the recipient to decrypt with, ornullwhen the JWE names one keyinput- JWET multipart file (header + envelope)output- destination for decrypted plaintext- Returns:
- metadata about the decryption operation
- Throws:
AnkaSecureSdkException- if decryption fails
-
reencryptFileStream
public ReencryptResult reencryptFileStream(String newKid, String sourceKid, Path input, Path output) throws AnkaSecureSdkException Server-side re-encryption of a ciphertext with a new key.This implementation extracts the original JWET header JSON and forwards it as-is to the API without parsing, ensuring perfect forward compatibility with server-side fields unknown to this SDK version (e.g.,
anka_composite_mode, future extensions).Zero-overhead design: The header is treated as an opaque string that is simply forwarded to the server. No deserialization, no validation, no conditional logic based on key type.
- Specified by:
reencryptFileStreamin interfaceco.ankatech.ankasecure.sdk.internal.service.CryptoService- Parameters:
newKid- public-key identifier for the new ciphertextsourceKid- the recipient this re-encryption replaces, ornullwhen the JWE names one keyinput- JWET multipart file (header + envelope)output- destination for the re-encrypted file- Returns:
- metadata about both old and new keys used
- Throws:
AnkaSecureSdkException- if re-encryption fails
-
encryptBytes
Encrypt raw bytes with a server-side **public** key.- Specified by:
encryptBytesin interfaceco.ankatech.ankasecure.sdk.internal.service.CryptoService- Parameters:
kid- key ID in the platform (must not benull)plaintext- data to protect (must not benull)- Returns:
EncryptResultexposing the Compact JWE token and metadata- Throws:
AnkaSecureSdkException- on validation or remote failure
-
decryptBytes
public co.ankatech.ankasecure.sdk.internal.service.CryptoService.DecryptBytesHolder decryptBytes(String recipientKid, String jweToken) throws AnkaSecureSdkException Decrypt a JWE (Compact or General JSON) that is already in RAM.- Specified by:
decryptBytesin interfaceco.ankatech.ankasecure.sdk.internal.service.CryptoService- Parameters:
recipientKid- the recipient to decrypt with, ornullwhen the JWE names one key (required by the server when it is addressed to several)jweToken- textual Compact JWE (UTF-8, not Base64 wrapped)- Returns:
CryptoService.DecryptBytesHoldercontaining plaintext and metadata- Throws:
AnkaSecureSdkException- on validation or remote failure
-
reencryptBytes
public ReencryptResult reencryptBytes(String newKid, String sourceKid, String jweToken) throws AnkaSecureSdkException Re-encrypt a JWE in memory so it becomes protected bynewKid.- Specified by:
reencryptBytesin interfaceco.ankatech.ankasecure.sdk.internal.service.CryptoService- Parameters:
newKid- key that must protect the data after rotationsourceKid- the recipient the re-encryption replaces, ornullwhen the JWE names one keyjweToken- current Compact JWE (text form)- Returns:
- metadata for old/new keys plus the refreshed JWE token
- Throws:
AnkaSecureSdkException- on validation or remote failure
-