Giter Site home page Giter Site logo

Comments (7)

Kejiasir avatar Kejiasir commented on June 15, 2024 1

Hello, @csjones ,thank you for your reply, CryptoKit has a constructor to create a PrivateKey from a pem private key, but it only supports iOS 14 or above. I think it would be great if secp256k1.swift could support importing pem to create a PrivateKey.

CryptoKit example:

if #available(iOS 14.0, *) {
        let prikey = """
            -----BEGIN PRIVATE KEY-----
            MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgeeKPvGwZ92ghbN4+
            bReH21oDBQnD1f0/HOs8usdsdSDuouioi77DSY9sdsa9dya89d8s/aDrJxITXeXo
            /QFWM+SKDJLdfsfw4A546Jsdf/ipgevqznDVKTDJxoOK6DliXS20GQjZZ9T6xx3D
            ZqoY65zp
            -----END PRIVATE KEY-----
            """
        
        let message = "Test signature message".data(using: .utf8)!
        let privateKey = try? P256.Signing.PrivateKey(pemRepresentation: prikey)
        
        guard let signature = try? privateKey?.signature(for: message) else { return }
        
        let signDataBase64String = signature.derRepresentation.base64EncodedString()
        print("CryptoKit: \(signDataBase64String)")
        
        let publicKey = privateKey?.publicKey
        let isValidSignature = publicKey?.isValidSignature(signature, for: message)
        print("CryptoKit: \(isValidSignature)")
}

from secp256k1.swift.

csjones avatar csjones commented on June 15, 2024

Hey @Kejiasir 👋

Importing a pem private key isn't supported yet. Do you have a specific use case? I can investigate your use case, check out how Apple supports pem, and see about bringing the feature into this package.

from secp256k1.swift.

csjones avatar csjones commented on June 15, 2024

Hey @Kejiasir - want to double check, are you sure you need seccp256k1? I ask because CryptoKit uses seccp256r1 and it wouldn't matter what iOS version this package supports.

from secp256k1.swift.

Kejiasir avatar Kejiasir commented on June 15, 2024

Hey @csjones Yes, I need to use the ecdsa signature algorithm to generate signatures in versions below iOS14. Since I need to create a PrivateKey by importing a pem key, so far, I have not found a more suitable third-party library to achieve it.

from secp256k1.swift.

csjones avatar csjones commented on June 15, 2024

Hey @Kejiasir how are you generating these pem keys?

from secp256k1.swift.

Kejiasir avatar Kejiasir commented on June 15, 2024

Hey @csjones This is Apple's official document, and I followed this guideline. Generate keys for in-app purchases

from secp256k1.swift.

csjones avatar csjones commented on June 15, 2024

Hey @Kejiasir I think this package isn't what you need based on those Apple instructions and none of the documentation mentions secp256k1. Are you aware of this Swift package? It has support prior to iOS 13.

I am still planning to add PEM key support but I don't have a good test case for basing the implementation on.

from secp256k1.swift.

Related Issues (20)

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.