Comments (3)
Thanks for the quick reply,
I found the problem: I was using an old version of the library (WebCrypto.js) that had a problem and won't decrypt the code; after using the new version everything is working correctly.
Thanks again for the help,
bye Vincenzo
from webcrypto.swift.
Hi Vincenzo,
I managed to get it working. You were almost there!
The problem was with the way you converted your encrypted string to Data
.
Your encrypted string is base64-encoded, you need to decode it before converting it to Data
.
Here's a helper function that does both the decoding and conversion to the Data
format:
let input = Data(base64Encoded: base64String, options: .ignoreUnknownCharacters)!
And here's a working example:
let base64String = "6yVJAXlqQGli1wJWlcQoFeQVD/BQR3TDQNJZe1/gQQ5tCN6pRe0gOlAkv1CWTA3ZjXdntMooxI7bm9rphV+DyqGyXRo34Ou38v+GqnSfY5N3m30GH3ieUa20RxdX9cUmtQCxJaDC47C79ybWkFRuXWHmqONVFxXVe4ZqyZBDy+a2zLxLufHEB9mJkH5DEID1d6bcRteONAb7KYbFkJLGbQ=="
let input = Data(base64Encoded: base64String, options: .ignoreUnknownCharacters)!
let plainPassword = "pd$83j@Fs3s13bZP"
let plainIV = "aNdh284629324F32"
let key = crypto.hexEncodedStringFromData(Data(plainPassword.utf8))
let iv = crypto.hexEncodedStringFromData(Data(plainIV.utf8))
crypto.decrypt(data: input, key: key, iv: iv, callback: {(decrypted: Data?, error: Error?) in
print(String(data: decrypted!, encoding: .utf8)!)
})
Thanks for the concise code samples,
Hope this helps!
from webcrypto.swift.
Also, take a look at the Data types conversion section of the README for more information.
from webcrypto.swift.
Related Issues (14)
- Can't decrypt the aes 128 encrypted string HOT 2
- Unable to load WebCrypto.js on iOS 9.3-9.3.3 HOT 3
- Hashing inconsistency in the web version
- Uncaught ReferenceError: md5blk is not defined
- Get crypted String HOT 1
- Want to decrypt with password for 128 bit encryption? HOT 2
- About the CryptoSwift performance result you compare. The value It's not right. HOT 2
- Convery crypto.js algorithm to Swift HOT 5
- CryptoJS result VS WebCrypto
- How to use decrypt function inside cellForRowAtIndexPath of tableView, as its an escaping closure
- Use of JavascriptCore framework to evaluate javascript then Webkit HOT 1
- RunLoop.current.run EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
- Not working in iOS 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webcrypto.swift.