RSA_Swift 是一款轻量级的 Swift 版本的框架,框架功能包括:RSA 加密/解密字符串、RSA 加密/解密 Data、字符串的 MD5、文件的 MD5 值的获取。
github 上 Swift 版本的 RSA 加密/解密框架也有,但最近使用的几个,总是会出现这样或那样的问题,所以就写了这个框架,附带的加上比较常见的功能:字符串的 MD5、文件的 MD5 值的获取。
对于文件的 MD5 值的获取,是将文件分块读出并且计算 MD5 值的方法,有别于文件一次性读出并且计算 MD5 值的方法。
To run the example project, clone the repo, and run pod install from the Example directory first.
RSA_Swift is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod ‘RSA_Swift‘
rsa 加密字符串和解密字符串/// 注:rsa 加密 Data 和解密 Data 方法使用与`rsa 加密字符串和解密字符串`类似,这里就不写示例代码了
let filePath = Bundle.main.path(forResource: "public_key", ofType: "der")
let encryptString = "abcdefg"
print("要加密的字符串:\(encryptString)")
/// Encrypt
RSA.rsaEncrypt(filePath, encryptString) { (encryptedString) in
print("加密后的字符串:\(encryptedString ?? "")")
let filePath1 = Bundle.main.path(forResource: "private_key.p12", ofType: nil)
/// Decrypt
RSA.rsaDecrypt(filePath1, "ios", encryptedString, { (decryptedString) in
print("解密后的字符串:\(decryptedString ?? "")")
})
}
MD5 值guard let filePath = Bundle.main.path(forResource: "test_file_md5", ofType: "png")
else {
return
}
print("文件的 MD5 值:\(filePath.md5_File() ?? "")")
MD5let str = "字符串的MD5"
print("字符串的MD5:\(str.md5())")
RSA_Swift is available under the MIT license. See the LICENSE file for more info.
如果你有什么建议,可以关注我的公众号:iOS开发者进阶,直接留言,留言必回。

iOS SKStoreProductViewController的应用
CocoaPods开源库的搭建
CocoaPods搭建私有库
CocoaPods搭建私有库遇到问题
CocoaPods私有库的升级维护
SKStoreReviewController之程序内评价
App应用程序图标的动态更换
开源框架 MGJRouter_Swift
iOS的MVP设计模式
iOS插件化
iOS FMDB的使用
Swift之ReactiveSwift
OC之ReactiveCocoa
OC之ReactiveCocoa进阶
iOS 性能考虑
原文:https://www.cnblogs.com/MrXie821385843/p/10364686.html