-
Notifications
You must be signed in to change notification settings - Fork 0
Crypto actions
Boriss Melikjan edited this page Apr 6, 2026
·
1 revision
Before you can encrypt data files, you need to get auth certificate. For that use search method from CryptoLib OpenLdap class:
/// @mockable
@MainActor func search(identityCode: String) async -> (
addressees: [Addressee],
tooManyResults: Bool
)let result = await openLdap.search(identityCode: searchText)
if result.tooManyResults {
recipients = []
errorMessage = "Too many results"
} else {
recipients = result.addressees
}To encrypt files, use encrypt method of CryptoLib CryptoContainer class:
@MainActor
public static func encrypt(
containerFile: URL,
dataFiles: [URL],
recipients: [Addressee]
) async throws -> CryptoContainerProtocol let encryptedContainer = try await CryptoContainer.encrypt(
containerFile: containerFile,
dataFiles: dataFiles,
recipients: recipients
)try await Encrypt.encryptFile(
containerFile.resolvedPath,
withDataFiles: cryptoDataFiles,
withAddressees: recipients
)Created container is in CDOC or CDOC2 format.
To get info about CDOC or CDOC2 container, use open method of CryptoLib CryptoContainer class:
static func open(containerFile: URL) async throws -> CryptoContainerProtocolreturn try await open(containerFile: firstFile)guard let cdocInfo = try Decrypt.cdocInfo(renamedContainerFile.resolvedPath) as? CdocInfo else {
throw ...
}To decrypt CDOC or CDOC2 container, use open method of CryptoLib CryptoContainer class:
@MainActor
public static func decrypt(
containerFile: URL,
recipients: [Addressee],
cert: Data,
cardCommands: CardCommands,
pin: SecureData,
fileManager: FileManagerProtocol = Container.shared.fileManager()
) async throws -> CryptoContainerProtocollet returnData = try await CryptoContainer.decrypt(
containerFile: containerFile,
recipients: recipients,
cert: cert,
cardCommands: cardCommands,
pin: pin1Number,
)let decryptedData =
try await Decrypt.decryptFile(
containerFile.resolvedPath,
withCert: cert,
withToken: SmartToken(card: cardCommands, pin1: pin)
)