Git Product home page Git Product logo

Comments (6)

amitaymolko avatar amitaymolko commented on August 11, 2024

Currently the library only supports No Padding pem certificates.
Your certificate is PKCS1: https://lapo.it/asn1js/#30820122300D06092A864886F70D01010105000382010F003082010A0282010100C7D55A9FEB429283C34ECFD4F0A0259392C3519EDFEB8DCC3F3E7494A4F50896E1A2C79F005AC8EC23FE8E8CBAD51382C76258791A3A06B03DF286A73E6E66D1F72A2C357C8294FF2D849BB1A7D4F5EEEDF26913774E76422988F1499919B85C8392F671B384F4F48D152A8647EBCD145811618301BB8B8DDC7092AD6F0DE8E6EA9500B3E7B106AE945B7C076A2CA8D7C6D5CE84BE14C55D3A81E5141738DF414D08928EB1B21449BC2578F92205F4C44F4D79D4B0C59C342B11286417C7A74C404B21FCF57A71722821D56E3EA6600965CE7B24C8648FC79A9BFEECE91A06D0D111ADEBBC3157384D7BA635D15DDD5021441F729CAD94FF2C70B205ACEF0CDB0203010001

You are welcome to make a PR, not sure when I would be able to get add this feature.

from react-native-rsa-native.

co-kevin avatar co-kevin commented on August 11, 2024

First of all thank you very much you can provide the library. Is the best I ever used the react native rsa library.

I know bouncycastle(Java) library can solve that. I don't understand Objective-C, sorry.

private static PublicKey getPublicKey(String pemKey) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
    Reader keyReader = new StringReader(pemKey);
    PEMReader pemReader = new PEMReader(keyReader);
    Object pemObject = pemReader.readObject();
    RSAPublicKeySpec keySpec;
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    if (pemObject instanceof JCERSAPublicKey) {
        JCERSAPublicKey jcersaPublicKey = (JCERSAPublicKey) pemObject;
        keySpec = new RSAPublicKeySpec(jcersaPublicKey.getModulus(), jcersaPublicKey.getPublicExponent());
    } else {
        KeyPair keyPair = (KeyPair) pemObject;
        java.security.interfaces.RSAPublicKey rsaPublicKey = (java.security.interfaces.RSAPublicKey) keyPair.getPublic();
        keySpec = new RSAPublicKeySpec(rsaPublicKey.getModulus(), rsaPublicKey.getPublicExponent());
    }
    return keyFactory.generatePublic(keySpec);
}

Spongycastle should also support this feature, after I finish my work in hand I will try to make a PR.

from react-native-rsa-native.

amitaymolko avatar amitaymolko commented on August 11, 2024

Ok cool, If you provide android support it will definitely push us to add iOS support as well

from react-native-rsa-native.

co-kevin avatar co-kevin commented on August 11, 2024

I get add this feature, when i test on react-native app, i get a exception:

Cannot merge new index 69109 into a non-jumbo instruction

This code works on sample java project.

private PublicKey pkcs1ToPublicKey(String publicKey) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
    Reader keyReader = null;
    try {
        keyReader = new StringReader(publicKey);
        PEMParser pemParser = new PEMParser(keyReader);
        PemObject pemObject = pemParser.readPemObject();
        RSAPublicKey rsaPublicKey = RSAPublicKey.getInstance(pemObject.getContent());
        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(rsaPublicKey.getModulus(), rsaPublicKey.getPublicExponent());
        KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM);
        return keyFactory.generatePublic(keySpec);
    } finally {
        if (keyReader != null) {
            keyReader.close();
        }
    }
}

And added dependencies

compile 'com.madgag.spongycastle:prov:1.56.0.0'
compile 'com.madgag.spongycastle:bcpkix-jdk15on:1.56.0.0'

from react-native-rsa-native.

amitaymolko avatar amitaymolko commented on August 11, 2024

@hookszhang
Ok man, I'll test your code when I get the time.
Thanks for contributing!

from react-native-rsa-native.

amitaymolko avatar amitaymolko commented on August 11, 2024

Fixed in #14

from react-native-rsa-native.

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.