Hash 提供了一种便捷的方式,可以将 Swift Data 或 String 格式的消息转换为消息摘要(哈希),或者使用以下哈希函数之一生成 HMAC:MD2、MD4、MD5、SHA-1、SHA224、SHA-256、SHA-384 或 SHA-512。同时还支持使用 AES-128、AES-192 或 AES-256 进行加密和解密。
CocoaPods 是一个依赖管理器,可将依赖项集成到您的 Xcode 工作区中。 要使用 Ruby gems 安装它,请运行
gem install cocoapods
要使用 Cocoapods 安装 Hash,只需将以下行添加到您的 Podfile 中
pod "Hash"
然后运行命令
pod install
有关更多信息,请参阅此处。
Carthage 是一个依赖管理器,它生成一个二进制文件,用于手动集成到您的项目中。 可以通过 Homebrew 使用以下命令安装
brew update
brew install carthage
为了通过 Carthage 将 Hash 集成到您的项目中,请将以下行添加到您项目的 Cartfile 中
github "rwbutler/Hash"
从 macOS 终端运行 carthage update --platform iOS
以构建框架,然后将 Hash.framework
拖到您的 Xcode 项目中。
有关更多信息,请参阅此处。
Swift Package Manager 是 Swift 模块的依赖管理器,并且作为 Swift 3.0 的一部分包含在构建系统中。 它用于自动化依赖项的下载、编译和链接。
要将 Hash 作为依赖项包含在 Swift 包中,请将该包添加到您的 Package.swift
文件中的 dependencies
条目中,如下所示
dependencies: [
.package(url: "https://github.com/rwbutler/Hash.git", from: "1.0.0")
]
有关如何使用 Hash 的示例,请参阅 Example 目录中的示例应用程序。
if let hash = Hash(message: "Hello World!", algorithm: .sha256) {
print(hash)
}
打印输出
7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069
if let hash = HMAC(message: "Hello World!", key: "123", algorithm: .sha1) {
print(hash)
}
打印输出
5471001127ed5f6261576c66033d9cbe37c7c91e
当前支持的加密算法有:AES-128、AES-192 和 AES-256。
if let cipherText = CipherText(message: "Hello World!", key: "01234567890123450123456789012345", iv: "0123456789012345", algorithm: .aes256) {
print(cipherText)
}
打印输出
6a790fe6c15590a6434d3ee3a866d327
当前支持的解密算法有:AES-128、AES-192 和 AES-256。
if let cipherText = Data(hex: "6a790fe6c15590a6434d3ee3a866d327"),
let keyData = "01234567890123450123456789012345".data(using: .utf8) {
let plainText = PlainText(message: message, key: keyData, iv: "0123456789012345".data(using: .utf8), algorithm: .aes256)
print(plainText)
}
打印输出
Hello World!
Hash 在 MIT 许可证下可用。 有关更多信息,请参阅 LICENSE 文件。
AnimatedGradientView |
---|
![]() |
Cheats | Connectivity | FeatureFlags | Skylark | TypographyKit | Updates |
---|---|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
cdd
即可快速清除 DerivedData 目录。Config Validator | IPA Uploader | Palette |
---|---|---|
![]() |
![]() |
![]() |