Android Question Calculate the java.security.Key

Francesco Maresca

Member
Licensed User
Longtime User


I thank you for the help you are giving me.
My problem now is another:
1 - From the text file I read a key
2 - The key is an RSA PRIVATE KEY
3 - Convert the key read from RSA PRIVATE KEY in PRIVATE KEY

How can I perform the third operation?
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
3 - Convert the key read from RSA PRIVATE KEY in PRIVATE KEY

This IS the private key! Maybe you are getting confused with RSA.

RSA uses two keys: Private and Public. In OpenSSL you generate both with:

B4X:
openssl genrsa  -out PrivateKey.pem 2048 'or higher
openssl pkcs8 -topk8 -inform pem -in PrivateKey.pem -outform pem -nocrypt -out C:/xampp/htdocs/rsa/PrivateKey.pem
openssl rsa -pubout -in PrivateKey.pem -out C:/xampp/htdocs/rsa/PublicKey.pem

With this we have

PrivateKey.pem = Private key with headers and "eye friendly"
PublicKey.pem = Public key with headers and "eye friendly"

In B4x we need to adapt it a bit (see my code) and load it as shown in my code. If you and I want to share RSA encrypted data I will give you MY Public Key and you are giving me your Public Key. The Private Keys are top secret!!!! If I send you a message I encrypt it with YOUR Public Key and only you can decrypt it with your Private Key and vice versa.

So you have 2 Ciphers and 2 KeyPairGenerators (yours and mine). You generate the keys in B4x in the first and LOAD my Public key in the second. To load a OpenSSL pem key, the key has to be adapted (see my code).

If you have further questions, please describe the complete process. Example: My app needs to share encrypted data with xxxx, etc. You need to understand what your needs are (not in small steps, the whole thing like "where are the keys from, how do I exchange them, etc.).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…