Comments (6)
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.
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.
Ok cool, If you provide android support it will definitely push us to add iOS support as well
from react-native-rsa-native.
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.
@hookszhang
Ok man, I'll test your code when I get the time.
Thanks for contributing!
from react-native-rsa-native.
Fixed in #14
from react-native-rsa-native.
Related Issues (20)
- Incompatible Format
- Using RSA.signWithAlgorithm throws an error with some algorithms
- MIT License issue
- RSA decryption doesn't works with newest react native version 0.68 HOT 1
- fatal error: module map file ... react_native_rsa_native.modulemap not found HOT 1
- Android 8.1.0
- RSAECNative.swift line 357_ RSAECNative._encrypt(data:) HOT 2
- RSAKeychain - do key pairs get shared across devices with same iCloud account?
- On iOS RSAKeychain.getPublicKey returns an object instead of a string HOT 1
- After upgrade from v1 to v2 the keys are lost on iOS devices HOT 1
- [Unhandled promise rejection: TypeError: null is not an object (evaluating '_reactNativeRsaNative.RSA.generateKeys')] HOT 8
- Open to maintain library HOT 1
- IOS Build fails "include of non-modular header"
- Inconsistent parameter order
- Differently formatted keys on android and iOS HOT 1
- Improper key description in Readme file
- How to test code using this library?
- What algorithm is used to sign a message?
- This Lib works with Expo? HOT 2
- Could not build Objective-C module 'react_native_rsa_native' HOT 1
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 react-native-rsa-native.