如何在Ruby中使用Triple-DES ECB模式加密数据?
下面的示例代码在Swift中,而我正在寻找相同的Ruby实现。在红宝石中应该使用什么与Swift语言的IDZSwiftCommonCrypto
等效的东西?
func encrypt(pin: String, mobile: String, zpk: String) throws -> String {
do {
let plainText = try getPlainText(pin: pin, mobile: mobile)
let key = try getKey(p: p)
let cryptor = Cryptor(operation: .encrypt,
algorithm: .tripleDES,
options: .ECBMode,
key: key,
iv: [UInt8]())
if let cipherTextInBytes = cryptor.update(plainText)?.final() {
let cipherText = hexString(fromArray: cipherTextInBytes, uppercase: true)
return cipherText
}
}
}