Open tkhabbab opened 4 years ago
I am unable to use this method "- (NSData )encrypt:(NSData )plainText key:(NSString )key iv:(NSString )iv" in my project. I can successfully encrypt a string but unable to encrypt a Data . Every time I got error "Can't convert Value of type Data to expected argument type String". Please resolve this issue as soon as Possible.
In java they use this class now I want to use it in ios swift
public class CryptLib {
// System.out.println(_out); return _out; // return encrypted/decrypted string }
// * @param _iv
@throws BadPaddingException */
public String encrypt(String _plainText, String _key) throws InvalidKeyException, UnsupportedEncodingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { // return encryptDecrypt(_plainText, _key, EncryptMode.ENCRYPT, _iv); String key = _key; try { key = SHA256("HALTech^%$#@!Trn", 32); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); }
}
/***
@throws BadPaddingException */ public String decrypt(String _encryptedText, String _key) throws InvalidKeyException, UnsupportedEncodingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { String key = _key; try { key = SHA256("HALTech^%$#@!Trn", 32); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return encryptDecrypt(_encryptedText, key, EncryptMode.DECRYPT, _key); // return encryptDecrypt(_encryptedText, _key, EncryptMode.DECRYPT, _iv); }
/***
@throws UnsupportedEncodingException */
public static String SHA256 (String text, int length) throws NoSuchAlgorithmException, UnsupportedEncodingException {
} }