Open pke opened 3 years ago
Yea that makes sense, do you have some example data I can test with? Just some throw away private key?
Thanks for your swift response! -----BEGIN RSA PRIVATE KEY----- MIIJJwIBAAKCAgEA9XLTJk9hmXYksPywZvWOXiSVBZImd2/1Psoz5zYBdfDkzBmb R++7XgMWVhyaTkTkSCjKKQiT+4Qs6HbEZZXTpidtQJQZJcDQMx6NuxwkBBYOSCYs LBgqEltGsyuKLRt0lExitIOFtJaJmxR3FFwN0mkCwdqAOcI4VOOmqBTp7BdccwxZ WWYBmwKsOeYWcZChksJuTiRBJdGCyI5JwWJDOY5lLu4B62jusAelisoTCzC+kKiC tKohTW0BBxLlZ6wW8ZU3/63fB3zZLVhCm7HUrRmml7xzQ4Ifqoqi4aNTdH+moeJD /4+4Fx/O2/rhDDWVVx1arQC3+oK6XUfrq7eVtuJiItAd4b9qAQhq5OHwLQ6Wlwr2 hUFZ0pq/A78hQ9jPjkKUA9g3WLHazUJvyM92S815V28ocrZNOpPOdjycRqAuslvM PO41V398+CtJue6UEqP0euB75wdGdhBkRKpj687YWGuGlbOVSKfu5HGnWrsR8zIi hBjTyzzozY0KA0MZmuVKVJR0M2r5406NfWmoNdowRAbRr7OPkpoZEOKKmlx0BByN 748GtWuDY/USzn8Q5BJ7a/VeWaWxDYq323J9jkFdNkbEDsYP3tstDbMUUr1HCnJz rOVUJEpy9sdKc22r/1enF+sGkKGqQEg8/vBQN4t85nHxSNoFxZMhbWS1wPsCAwEA AQKCAgAy/aLOD6m4BupCdoxzJ0pnVnQ7Dwy8vV6Wp802mGqfROdTW3J99FjZhAys 4Q5RelBuiULOWYDcvK3TsXDFpeWtW/1/cAT1aeQW6p8JIyR8UNSwunVsx6xd2eaL LF1tV4nVkTTkSXqKdMerlwnSCfm5H6W5/hmrZiTrxcuGmamrKYNER2l8gAuPV3PO J3W8LA7U/V2LEE8Uez0PSzgZW7+ZgnKU2E8/x7HmkgAbIDXqmjrMtKVKwRlgC2gu Pwe3jPHLSHO0wztVQ+OeXvqfe8cyGu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ATE KEY-----
While we are at it:
const decryptedBytes = await RNSimpleCrypto.RSA.decrypt(RNSimpleCrypto.utils.convertUtf8ToArrayBuffer(recipient.encryptedContent.content), privateKeyString)
Crashes the app. recipient.encryptedContent.content
is a string with binary data from a decoded PKCS#7
The following is what I see on the console, but of course console tries to print in UTF-8 encoding.
[Fri Feb 26 2021 18:00:03.416] LOG recipient {"encryptedContent": {"algorithm": "1.2.840.113549.1.1.1", "content": ".¥uÀÜ´
5èE&3ý®D\>°äßó:F+I¿ûxmX¬>qÌSF7þdÀ|õ\"çÇó~>Ìêï×®eEö÷fê@ÃÃÅÉ ãÛp¡C&1ѺºÉâ²l!¢±ËË\\)
Tic>+SÎR®ÌDÁÏ÷}õÜ\\§ õÝ{ÄáÂîSõÝa¢ÂD0¯Ò
Ì_³¾Ñ̯Q_ÏN7ÍÚMV¿
¶¹µûûÊ]ùVwvò%
aÂ9øòÓùÏ¡7®DY6壬¡õçÆv.}Ûi'öí©
ôL«üSoª]èå¦WÈa-^¹[²- -R
qfª®FÏê>ýÍú{.ÐqÔ9h×$³%j¥´çv»ñiÜÅâzN¾DÉ Úçñh,«=B_D¹¦a´Èõ¤»h¯ÔÇoÃc¸zéú7nÏ)Ö\\
ìËù÷«®=¯f$äPå¢ V*'¥ö¸:nÓ]ä\\jԣѨ£~9¾Ð°vbSwA¯>mJZ§
pzÚ×7!îi¡<,Á-¡_$nÒ¸åè1t±ò«G¸¡µÄn½¢Ûu¾¨ñTî{2ºì·çª\\䵧uÒoamY{^8z:ö¢ïfµ"}
So in which representation should RSA.decrypt
get its first argument?
I think it is different for iOS / Android. Both expect a hash with both public key and a private one. iOS seems to encode in base64, Android uses an array buffer. Are you trying to generate a set of public / private keys using some memory storage? We could try to create a function to format the keys properly given base64 public and private key input.
Would it be possible to catch errors on the native side to not crash the app when exceptions happen on native side?
When handing in invalid data to the RSA functions, like a private key to
RSA.encrypt
, the app crashes instantly.