[ad_1]
My goal is to encrypt a specific file and put it aside in Paperwork Listing. I may have used Apple Encrypted Archive to encrypt however the file decryption needs to be achieved on my server (Java).
The java code I am utilizing to encrypt on the android app.
public static void performEncrypt(File inputFile, File outputFile) {
strive {
String SECRET_KEY = "MY_SECRETE_KEY";
String SALT = "MY_SALT_KEY";
// Producing Secrete Key
byte[] iv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
IvParameterSpec ivspec = new IvParameterSpec(iv);
SecretKeyFactory manufacturing unit = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec spec = new PBEKeySpec(SECRET_KEY.toCharArray(), SALT.getBytes(), 65536, 256);
SecretKey tmp = manufacturing unit.generateSecret(spec);
SecretKeySpec secretKey = new SecretKeySpec(tmp.getEncoded(), "AES");
//Studying Enter File Bytes
byte[] inputBytes = Recordsdata.readAllBytes(inputFile.toPath());
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivspec);
// Performing Encryption
byte[] outputBytes = cipher.doFinal(inputBytes);
//Writing to output file
FileOutputStream outputStream = new FileOutputStream(outputFile);
outputStream.write(outputBytes);
outputStream.shut();
} catch (Exception e) {
e.printStackTrace();
}
}
I have been making an attempt to copy the above operate is Swift however I’m having hassle discovering the Swift different of those Java Courses. How do I carry out encryption utilizing my salt and secrete key ? The closest article I may discover associated to my subject was this, however I could not perceive it.
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
let documentDirectory = FileManager.default.urls(for: .documentDirectory,in: .userDomainMask)[0]
let tempFileName = documentDirectory.appendingPathComponent("temp.enc")
do{
let iv: [UInt8] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
let fileToEncrypt = strive Information(contentsOf: urls.first!)
let operations = CCOperation(kCCEncrypt)
let algorithm = CCAlgorithm(kCCAlgorithmAES)
let choices = CCOptions(kCCOptionPKCS7Padding)
}catch{
print("Error")
}
}
The final choice for me can be to transform my Java code into Goal-c utilizing j2objc. However as a newbie in iOS that appears a bit painful .
[ad_2]
