Kitura / Kitura/BlueCryptor

Invalid Triple-DES encryption result

Open
#75 0 comments 0 reactions 1 assignee Claimed by @adam-rocska View on GitHub
question
Dominant language
Swift
Stars
192
Forks
48
PR merge metrics
No merged PRs in 30d

Description

Hi everyone,

I'm going to implement the Triple-DES to encrypt a password and I'm using the following command to validate the encryption output.
![Screen Shot 2022-06-01 at 3 47 48 PM](https://user-images.githubusercontent.com/55052492/171421163-e3b62987-bbfb-48fc-8b59-d561a10e6a81.png)

but I got a different encryption result.

Here's my code
```
func tripleDesEncrypt(inputStr: String, keyStr: String) -> String? {
let key = CryptoUtils.byteArray(fromHex: keyStr)
let iv = CryptoUtils.byteArray(fromHex: "0000000000000000")
let plainText = CryptoUtils.byteArray(fromHex: inputStr)

var textToCipher = plainText
if plainText.count % Cryptor.Algorithm.tripleDes.blockSize != 0 {
textToCipher = CryptoUtils.zeroPad(byteArray: plainText, blockSize: Cryptor.Algorithm.tripleDes.blockSize)
}
do {
let cipherText = try Cryptor(operation: .encrypt, algorithm: .tripleDes, options: .pkcs7Padding, key: key, iv: iv).update(byteArray: textToCipher)?.final()

print(CryptoUtils.hexString(from: cipherText!))

} catch let error {
guard let err = error as? CryptorError else {
return nil
}

print(err.description)
}

return nil
}
```

> **Input**
> inputStr: 0592389EDCBA96FF
> keyStr: 0123456789abcdeffedcba9876543210

> **Output**
> d9f8e02413307c829b81df2a39d8c603

The right output should be
a25fbc3a3ed409102e24eeb85aef49ae

Please advise.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.