Radioplayer / WRAPI-Java-SDK

0 stars 0 forks source link

problem creating RSA private key #2

Open carlol opened 2 years ago

carlol commented 2 years ago

Hi, I've downloaded the project and added the trial pem file and api_key but when I run the tests I get "problem creating RSA private key: java.lang.IllegalArgumentException: failed to construct sequence from byte[]: corrupted stream detected".

I'm doing something wrong or there is some missing update to the code?

Best regards.

spencer-aerian commented 2 years ago

Have you modifed the application.properties and test-application.properties file with the path to the pem file. The PEM file must be named as the apiKey that you were given as this is how it is extracted.

carlol commented 2 years ago

Hi,

yes we added the file as-is and put in the properties its absolute path (see the image).

Schermata 2021-09-30 alle 15 44 31

we get the following error: org.bouncycastle.openssl.PEMException: problem creating RSA private key: java.lang.IllegalArgumentException: failed to construct sequence from byte[]: corrupted stream detected

We imported the project in IntelliJ lik a maven project and we added the absolute path to .pem in .properties. Did we forget some steps?

Thank you in advance for your help,

Best regards,

CL

evrep commented 2 years ago

Hi, I'm Edoardo, Carlo's colleague. I work on iOS and I'm trying to implement your APIs. I'm not using the Java SDK (not possible on iOS), but I'm trying to translate the developer guide on your website in Swift. I'm having issues with the .pem file. Every RSA library I tried it seems to not recognize the private key as a valid one. I'm trying with "SwiftyRSA", "CryptorRSA" (two of the most popular) without any good result. I was wondering if you have had feedback from other iOS developers, or you can try to help us in other ways.

Basically, I'm trying to replicate the Java code on your website in this way:

let stringDate = stringDateText.data(using: .utf8)! let myPlaintext = CryptorRSA.createPlaintext(with: stringDate) let privateKey = try CryptorRSA.createPrivateKey(withPEMNamed: API_KEY, in: .main) let signedData = try myPlaintext.signed(with: privateKey, algorithm: .sha256) let stringSig = signedData?.base64String

var sig = "Signature keyId=" sig.append("\"") sig.append(API_KEY) sig.append("\"") sig.append(",algorithm=\"rsa-sha256\",signature=\"") sig.append(stringSig!) sig.append("\"")

The error I'm receiving is this: "Error code: -9999(0x-270F), Couldn't create key reference from key data"

Could you give a look at this code, please? Am I missing something? Thank you.

spencer-aerian commented 2 years ago

There is something wrong with the key and we are investigating internally.

evrep commented 2 years ago

Hi, after trying a little bit more we finally managed to get it work with the key we have, on iOS and Android. Probably there's a problem in the Java code you provide, because now we signed successfully the request with Swift and Kotlin.

spencer-aerian commented 2 years ago

Yes its something wrong inside the bouncycastle pem routines. Glad you got it working on iOS/Android. Still under investigation.

spencer-aerian commented 2 years ago

The pem file you have is actually a key. So to convert it to a pem do the following.. mv existing.pem existing.key openssl rsa -in existing.key -text > existing.pem

carlol commented 2 years ago

ok but it still is a private key, is ok for us to store it in the client applications?

spencer-aerian commented 2 years ago

Please contact Radioplayer directly regarding your usage of your key.

2Deimos commented 1 year ago

Hi, the issue was solved using the OpenSSL 1.1.1i version.

If you face this problem, probably the key given by Radioplayer was generated with higher version of OpenSSL and the readKey method probably fails because it doesn't recognize the bytes.

Just install the given OpenSSL version and rename the given key with a .key extension and do the command: openssl rsa -in <yourkey.key> -out <yourkey.pem>

Hope this helps!