当使用 Xcode 项目时
当使用 Swift Package Manager 清单时
选择包版本
1.0.7
develop (开发)
WhiteboxCryptographySDK
一个高性能的白盒密码学 (WBC) 框架,旨在以一种防止攻击者提取或逆向工程密码密钥和操作的方式来保护它们,即使代码和内存完全暴露。 该框架以一种抵抗各种旁路攻击和逆向工程攻击的方式实现密码算法。
- 安全密钥管理:保护密码密钥免受提取或分析。
- 加密算法:以白盒安全的方式提供各种加密算法的实现。
- 旁路攻击抵抗:采用防止在执行期间泄漏敏感数据的技术构建。
- 跨平台支持:与 iOS 和 macOS 应用程序兼容。
- 优化性能:旨在提供安全性和效率之间的平衡。
要使用 Swift Package Manager 将白盒密码学框架集成到您的 Xcode 项目中,请按照以下步骤操作
- 打开您的 Xcode 项目。
- 转到File > Swift Packages > Add Package Dependency。
- 输入此框架的存储库 URL:
https://github.com/DrDijkstra/WhiteboxCryptography
。 - 选择要使用的发布的版本范围或标签。
- 将以下内容添加到您的
Podfile
pod 'WhiteboxCryptography', '~> 1.0'
-
在终端中运行
pod install
。 -
在 Xcode 中打开
.xcworkspace
文件。
要将白盒密码学与 Carthage 集成,请将以下内容添加到您的 Cartfile
github "DrDijkstra/WhiteboxCryptography"
然后运行 carthage update
以构建框架。
要在您的项目中使用白盒密码学框架,请根据您的软件包管理器按照相应的说明进行操作
只需将框架导入到您的 Swift 文件中
import WhiteboxCryptography
- 确保根据软件包管理器的设置说明将框架正确集成到您的项目中。
- 仔细检查
WhiteboxCryptography
和WhiteboxCryptographySDK
的大小写,因为某些环境可能区分大小写。
// Example of how to use the encryption and decryption functionalities
import Foundation
import WhiteboxCryptography
// Initialize the WhiteboxCryptographySDK with a memory key
let memoryKey = "your-memory-key".data(using: .utf8)!
let whiteboxSDK = WhiteboxCryptographySDK(memoryKey: memoryKey)
// Sample data to encrypt
let data = "Sensitive data".data(using: .utf8)!
// Define a cryptographic key and IV
let encryptionKey = "your-encryption-key".data(using: .utf8)!
let iv = "your-iv-string".data(using: .utf8) // Optional IV for block ciphers
let algorithm: CryptoAlgorithm = .aes(keySize: 256, mode: .ecb, processingType: .regular) // Replace with the actual algorithm
// Encrypt the data
do {
if let encryptedData = try whiteboxSDK.encrypt(data: data, withKey: encryptionKey, iv: iv, algorithm: algorithm) {
print("Encrypted Data: \(encryptedData.base64EncodedString())")
// Decrypt the data
if let decryptedData = try whiteboxSDK.decrypt(data: encryptedData, withKey: encryptionKey, iv: iv, algorithm: algorithm) {
let decryptedString = String(data: decryptedData, encoding: .utf8)
print("Decrypted String: \(decryptedString ?? "Failed to decrypt")")
} else {
print("Decryption failed")
}
} else {
print("Encryption failed")
}
}catch(let error){
}
}
此实现中提供以下密码算法
-
AES(高级加密标准):一种用于保护数据的对称密钥加密标准。
- 支持不同的密钥大小 (
AESKeySize
) 和操作模式 (AESMode
)。
- 支持不同的密钥大小 (
-
DES(数据加密标准):一种对称密钥分组密码,以前是一种广泛使用的数据加密方法。
-
Triple DES (3DES):DES 的增强版本,将 DES 算法应用于每个数据块三次。
-
CAST:一系列为强加密设计的对称密钥分组密码。
-
RC2 (Ron's Code 2):一种用于硬件或软件环境的分组密码,通常用于文件加密。
该框架以白盒密码学方式支持这些算法的加密、解密和哈希。
本框架基于 MIT 许可证获得许可。 有关更多详细信息,请参见 LICENSE 文件。
我们欢迎您为改进框架做出贡献! 要贡献
- Fork 该存储库。
- 创建一个新分支 (
git checkout -b feature-branch
)。 - 进行更改。
- 提交更改 (
git commit -am 'Add new feature'
)。 - 推送到分支 (
git push origin feature-branch
)。 - 创建一个拉取请求。
如有问题或需要支持,请通过以下方式联系我们
电子邮件:deysanjay121@gmail.com
GitHub:https://github.com/DrDijkstra/WhiteboxCryptography