I need to generate Message Digest in Swift with SHA-256 variant with SALT. I am using CryptoSwift library in Swift for all the encryption/decryption. Now I am stuck at generating Message Digest which matches with Java code in Android as below. If someone can help me out of this. Thanks in advance.
Library I am using is Swift : CryptoSwift
Java Code used for generating MD with Salt using SHA-256
public static String generateMessageDigest(String message,String salt) {
try {
MessageDigest msDigest = MessageDigest.getInstance("SHA-256");
msDigest.update(salt.getBytes(StandardCharsets.UTF_8));
byte[] digest = msDigest.digest(message.getBytes(StandardCharsets.UTF_8));
return Base64.encodeBase64String(digest);
} catch(NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}
Note : I need MD with SALT
Finally, I managed to find the solution on my own and below is the answer.