Crypto actions - siimsuu1/MOPP-iOS GitHub Wiki
Searching addressees from LDAP
Before you can encrypt data files, you need to get auth certificate. For that use searchLdapData method:
NSString *identifier = @"47101010033";
MoppLibCryptoActions *sharedInstance = [MoppLibCryptoActions sharedInstance];
[sharedInstance searchLdapData:identifier success:^(NSMutableArray *ldapResponse) {
Addressee* addressee = (Addressee *)ldapResponse[0];
NSLog(@"Certificate: %@", addressee.cert);
NSLog(@"Given name: %@", addressee.givenName);
NSLog(@"Surname: %@", addressee.surname);
NSLog(@"Type: %@", addressee.type);
NSLog(@"Valid to: %@", addressee.validTo);
} failure:^(NSError *error) {
NSLog(@"Failed to get ldap response: %@", error);
}];
Encrypting files
To encrypt files, use encryptData method:
NSString *fullPath = @"path/to/file";
CryptoDataFile *dataFile = [CryptoDataFile new];
dataFile.filePath = @"path/to/dataFile";
dataFile.filename = @"dataFile";
Addressee *addressee = [Addressee new];
addressee.cert = [NSData new]; //valid certificate
NSArray* addressees = [NSArray arrayWithObjects: addressees];
NSArray *dataFiles = [NSArray arrayWithObject: dataFile];
MoppLibCryptoActions *sharedInstance = [MoppLibCryptoActions sharedInstance];
[sharedInstance encryptData:fullPath withDataFiles:dataFiles withAddressees:addressees success:^() {
NSLog(@"Data files successfully encrypted");
} failure:^(NSError* error) {
NSLog(@"An error occured with encryption: %@", error);
}];
Created container is in Cdoc format.
Parsing Cdoc and getting information about container
To get info about Cdoc container, use parseCdocInfo method:
NSString *cdocFullPath = @"path/to/file";
MoppLibCryptoActions *sharedInstance = [MoppLibCryptoActions sharedInstance];
[sharedInstance parseCdocInfo:cdocFullPath success:^(CdocInfo *cdocInfo) {
NSArray *addressees = cdocInfo.addressees;
NSArray *dataFiles = cdocInfo.dataFiles;
} failure:^(NSError *error) {
NSLog(@"An error occured with decryption: %@", error);
}];
Decrypting container
To decrypt Cdoc container, use decryptData method:
NSString *cdocFullPath = @"path/to/file";
NSString *pin1 = @"1234";
MoppLibCryptoActions *sharedInstance = [MoppLibCryptoActions sharedInstance];
[sharedInstance decryptData:cdocFullPath withPin1:pin1 success:^(NSMutableDictionary *decryptedData) {
for (NSString *filename in decryptedData) {
NSLog(@"Filename: %@", filename);
NSData *fileData = decryptedData[filename];
NSLog(@"File data: %@", fileData);
}
} failure:^(NSError *error) {
NSLog(@"An error occured with decryption: %@", error);
}];