/*
 @author: ideawu
 @link: https://github.com/ideawu/Objective-C-RSA
*/

#import <Foundation/Foundation.h>

/**加密/解密 工具类 (AES RSA Base64 MD5）*/
@interface RSATool : NSObject


#pragma mark RSATool 自带方法
// return base64 encoded string
+ (NSString *)encryptString:(NSString *)str publicKey:(NSString *)pubKey;
// return raw data
+ (NSData *)encryptData:(NSData *)data publicKey:(NSString *)pubKey;
// return base64 encoded string
+ (NSString *)encryptString:(NSString *)str privateKey:(NSString *)privKey;
// return raw data
+ (NSData *)encryptData:(NSData *)data privateKey:(NSString *)privKey;

// decrypt base64 encoded string, convert result to string(not base64 encoded)
+ (NSString *)decryptString:(NSString *)str publicKey:(NSString *)pubKey;
+ (NSData *)decryptData:(NSData *)data publicKey:(NSString *)pubKey;
+ (NSString *)decryptString:(NSString *)str privateKey:(NSString *)privKey;
+ (NSData *)decryptData:(NSData *)data privateKey:(NSString *)privKey;


#pragma mark 封装加解密方法:RSA➕AES➕Base64➕MD5➕RSA
/**AES加密 key-salt*/
+ (NSString *)AES128Encrypt:(NSString *)plainText key:(NSString *)key;
/**AES解密 key-salt*/
+ (NSString *)AES128Decrypt:(NSString *)encryptText key:(NSString *)key;

/**RSA加密-publicKey-公钥 （公钥加密 私钥解密）*/
+ (NSString *)RSAEncrypt:(NSString *)plainText key:(NSString *)publicKey;
/**RSA解密-privateKey-私钥 （公钥加密 私钥解密）*/
+ (NSString *)RSADecrypt:(NSString *)encryptText key:(NSString *)privateKey;

/**RSA私钥签名-privateKey-私钥 （私钥签名 公钥验签）*/
+ (NSString *)RSASignEncrypt:(NSString *)plainText key:(NSString *)privateKey;
/**RSA公钥验签-publicKey-公钥（私钥签名 公钥验签）encryptText-密文 plainText-明文*/
+ (BOOL)RSASignDecrypt:(NSString *)encryptText Encrypt:(NSString *)plainText key:(NSString *)publicKey;

/**base64加密*/
+ (NSString *)Base64Encrypt:(NSString *)plainText;
/**base64解密*/
+ (NSString *)Base64Decrypt:(NSString *)encryptText;

/**md5加密*/
+ (NSString *)md5Encrypt:(NSString *)plainText;

#pragma mark  其他
/**传入一个原始字典，依据ascii码从小到大排序，回传一个排好序的待签名字符串*/
+ (NSString *)sortArrWithDictionary:(NSDictionary *)dictionary;

/**删除字符串里的换行符 \r 和 \n */
+ (NSString *)deleteNewlineCharactersWithString:(NSString *)text;

#pragma mark  登录密码加密算法：MD5➕RSA
//+ (NSString *)getRSAStringFrom:(NSString *)pwd;

+ (NSData *)sha256:(NSString *)str;
+ (NSMutableString *)sha256_64:(NSString *)str;

+ (NSString *)sha256_8:(NSString *)str;
@end
