Coder Social home page Coder Social logo

821385843 / rsa_swift Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 2.0 166 KB

RSA_Swift是一个轻量级的框架,框架功能包括:RSA加密/解密字符串、RSA加密/解密Data、字符串的MD5、文件的MD5值的获取。

License: MIT License

Ruby 28.67% Swift 71.33%

rsa_swift's Introduction

RSA_Swift

RSA_Swift 是一款轻量级的 Swift 版本的框架,框架功能包括:RSA 加密/解密字符串、RSA 加密/解密 Data、字符串的 MD5、文件的 MD5 值的获取。

RSA_Swift 初衷?

githubSwift 版本的 RSA 加密/解密框架也有,但最近使用的几个,总是会出现这样或那样的问题,所以就写了这个框架,附带的加上比较常见的功能:字符串的 MD5、文件的 MD5 值的获取。

对于文件的 MD5 值的获取,是将文件分块读出并且计算 MD5 值的方法,有别于文件一次性读出并且计算 MD5 值的方法。

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

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() ?? "")")

字符串的 MD5

let str = "字符串的MD5"
print("字符串的MD5:\(str.md5())")

License

RSA_Swift is available under the MIT license. See the LICENSE file for more info.

作者其他框架

MGJRouter_Swift:一个高效/灵活的 iOS SwiftURL Router,完全实现了蘑菇街 Object-CMGJRouter 的所有功能。虽然 github 上也有一款参照 MGJRouter 仿写的 Swift 版框架,但是却去掉了 MGJRouter 的很多功能,不实用。

XWCountDownButton_OC:这是一个 Object-C 版本的小框架,可以使用 pod,应用于短信验证码倒计时。

XWCountDownButton:这是一个 Swift 版本的小框架,可以使用 pod,应用于短信验证码倒计时。

Author

如果你有什么建议,可以关注我的公众号:iOS开发者进阶,直接留言,留言必回。

输入图片说明

rsa_swift's People

Contributors

821385843 avatar

Stargazers

lausen Lau avatar nerver avatar Ryan Zhu avatar  avatar  avatar  avatar Felix avatar  avatar 华子 avatar  avatar  avatar  avatar zhiqingchun avatar  avatar SKY_WU avatar  avatar  avatar  avatar  avatar  avatar Romeo avatar  avatar  avatar

Watchers

James Cloos avatar  avatar SKY_WU avatar

Forkers

alexax harrysu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.