Coder Social home page Coder Social logo

Comments (3)

enx1998 avatar enx1998 commented on May 24, 2024 1

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.

etienne-martin avatar etienne-martin commented on May 24, 2024

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.

etienne-martin avatar etienne-martin commented on May 24, 2024

Also, take a look at the Data types conversion section of the README for more information.

from webcrypto.swift.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.