Convert rsa private key from PCKS#1 to PCKS#8 - rsa

May be who know how convert rsa private key from PCKS#1 to PCKS#8 by php or java.
php create rsa key by openssl_pkey_new() in format PCKS#1.
java can work only with private key by PKCS8EncodedKeySpec in format PCKS#8.
how can i convert key from format 1 to 8 in any of these languages?
now I have found a way out only to use external commands for create rsa keys in both formats (exec("openssl ...") by php and Runtime.getRuntime().exec("openssl ...") by java).
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
PHP 8.0
private key from php in pcks#1 format:
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA9Yd6QDqecP8c52W/WWz2GhiY/JKm2Mhc7h/kl+NAQr70nUF0
ASxLtJMVfR18PuBIoSgtTVVXBxB9bCM03Y0OtUjBzxj3Lo+dx05bGlIeC1VQ2FOF
EPSg75EG0Csjj0ctLvoer05aZpPhdfySgrVxtULCrpU7qucYDIlNsLuwCnNIdY6X
wqAcY/ZgSxNe68lFDZClE6+gVvrtoWiS3+L4aoc6oU6uQ73dUzf84NjPC4I4RElv
X1w/85H4RlEbCpgs4g62IB3qzI946Wy5wpei1kTCWaZj+GnrMHrw599ml2MrzteU
/GPov4iE1uoBKpiaM0PJ8LInrBuObL+9gP1LEQIDAQABAoIBAQDyVGuBdxmn9vLl
I9QvA88GRJ7CMlAAiAjIcavhiUaEWgn+J3rCKaDysXS1DuPw/tZQUOIdgIwricfw
cfMcc7s/i3bV2xMj3lVgP+LE4KWMlAD98bjU2kz5Bc+Op/Up1Zsv0Wd1qMSql2wg
Uk+cOE7pEuIpA1tnuzxOKzoFo8kFFYJGJtSFGsfNTW2CvWfE0d5GBVF3ASxNtqhr
dJAA8VGrLdzBbjfAZRZvnFiRekEWQ2zzoR8gPe6N9Vye3Y58tSqDoVjp6jyhLtB/
a/36FuLAR+vCz4JiVVrGXBX4BwIhqfVAamc1WnlvR0CFrza645luROohkWMzCu70
SuBiUvhRAoGBAP9I4wkE1R5GkieHwUGWEeQ3Q0y56tc7Uisdf3/U9RBHaMVGZo5U
hHynL9PKCUsfptfS/QzuWzbjX0kAVr/rIec0ayPt+vLWHLBHY4DMP2bORFB/Q3qj
sxCowGMzYiMLMNXMEMdRv/LLrOFwRo5kflMqKifbhk1BOMumSa7CPaYNAoGBAPY3
l9lmoD/JIDdadMlaqjrvHnGWiaGydEBsU4I55A+4g7fSFDy8lMtyG17rWeJoKxLH
d20aKZ5+NlbfMbMtmbqZbV0HuX/+SXVA+lTygphWZwGMc/b1Rx4dNMGPJ+Pr5R3M
GPTHNHSgLyXbYresk+X1xeOlJQ8CsnfdonD0ylwVAoGAbtwMG+KJWjhzR89gUUcG
RgDprOwf24/bQvXwZGbqdUNNcD3+U1jIoAlKb8KQ/pqkLZ1mXrMz0UY0HtOS2I0X
j/vnexbhn4rzsmmOAGSyM8bnS724ZA2quVVPFsU9nNJDRtTzhFsv7BQe41eKjFN/
uEXbQKvISsxECcwQu1+GvhECgYEAnZw4uBHZwvschFKDL+G51r/63PtgXwG9KQAu
9M3aD7Ytmx3/lmGhXhpNKxW9FBFagUruSAjXW32viyyUw/4MykYsm8C2HhjJLSXL
GVWkA6BLj9I46X1ZaQ2JF95ryprWr5xW3VonWgCwLauiJbFze2E4q+CrOFChrdlS
grwwTYECgYEAzlcKWEvAenaP3lkX0256BDQmbKeBGlqmqpO9xvrdX9ouq39BZJi1
8ZTyLJZdzhY9117ptyxcj0wdNwgUWN16XqVs7ADIRf2jAecFey/e+WjLM08+ip5w
q++Pn3f6m0GqtG/dQx0hchUMUW6PC1Wl3R9KWXlbsPCgCFdk2m5tXmg=
-----END RSA PRIVATE KEY-----

Related

Converting a .pem RSA Public and Private Key to .der X.509 certificates or JWK strings

I working on a project that uses JSON Web Tokens (JWT). I already have the code that creates the token that is signed by an RSA algorithm which was created by the openssl genrsa -des3 -out <private key file name>.pem 3076. I want to check the validity of the tokens I produce on the jwt.io website, but i need "[public/private] Key in...X.509 certificate, or JWK string format".
Format of private key:
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,4AE3D092CB847166
(The actual key)
-----END RSA PRIVATE KEY-----
Format of public key:
-----BEGIN PUBLIC KEY-----
(The actual key)
-----END PUBLIC KEY-----
Is there any command/tools that can be used to convert these into X.509 certificates or JWK strings?
I have already tried using the openssl x509 -in <public or private key file name>.pem -inform PEM -out <X509 certificate file name>.der -outform DER command.
That would always return this error:
unable to load certificate
140258002609472: error: 0909006C: PEM routines: get_name:no start line:../crypto/pem/pem lib.c:745: Expecting: TRUSTED CERTIFICATE
All of the commands have been run using the terminal from a replit project. I am not sure if that plays a role or not but I mention it just in case.
Do you use Windows? Check the encoding. Change to UTF-8 through the Notepad and create it.

how to get issuer from x509 certificate flutter?

How to find issuer from X509 certificate String (example given below) in flutter.
Thanks in advance.
-----BEGIN CERTIFICATE-----
MIICiTCCAjCgAwIBAgIUD3Kab5X9kqd9qN1fqB61TUlwbO0wCgYIKoZIzj0EAwIw
cDELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYDVQQH
EwZEdXJoYW0xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh
Lm9yZzEuZXhhbXBsZS5jb20wHhcNMjIxMDA2MTE0NzAwWhcNMjMxMDExMTAwNzAw
WjBHMTAwCwYDVQQLEwRvcmcxMA0GA1UECxMGY2xpZW50MBIGA1UECxMLZGVwYXJ0
bWVudDExEzARBgNVBAMTCnVzZXJUZXN0MDEwWTATBgcqhkjOPQIBBggqhkjOPQMB
BwNCAAQHJXgfHfQ8hDedBuSrthP9B6MB+f1W1FqfecFvvaOYlEsPHrSqATkVNQJ2
2tBxxKTwo7XF2gVqYn7QPUHqwVtgo4HQMIHNMA4GA1UdDwEB/wQEAwIHgDAMBgNV
HRMBAf8EAjAAMB0GA1UdDgQWBBQsiq8NZZh74PK/sMLfhWCq4IbMLjAfBgNVHSME
GDAWgBQdmRqOkqYG/lmxlNopkD99+TOH0jBtBggqAwQFBgcIAQRheyJhdHRycyI6
eyJoZi5BZmZpbGlhdGlvbiI6Im9yZzEuZGVwYXJ0bWVudDEiLCJoZi5FbnJvbGxt
ZW50SUQiOiJ1c2VyVGVzdDAxIiwiaGYuVHlwZSI6ImNsaWVudCJ9fTAKBggqhkjO
PQQDAgNHADBEAiBENbsQCzjg2vux5CWH9S8Xhg9fH2OBF9JZGSibwc4EHAIgBUEo
xQ5UhoNGZtArxDWA97ab7GspkeVF+6wwdakBRlM=
-----END CERTIFICATE-----
tried to decode x509 certificate PEM string, using x509b package, after that generated x509Certificate object from the giving PEM string.

How to convert PKCS#8 with password to PKCS#1 with JCE

I have a .pem file(PKCS#8) which has below sections in same file
-----BEGIN ENCRYPTED PRIVATE KEY-----
xx
xx
-----END ENCRYPTED PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
xx
xx
-----END CERTIFICATE-----
It is protected with passcode/password.
How can I decrypt this in java to PKCS#1 within JDK/JCE without BouncyCastle. I cannot even use the openssl commands.
How could I go about this?

How do I get public key info (RSA Bit) using jsrsasign?

I'm using this library jsrsasign. I'd like to know how get this information from certificate.pem
Public Key info: RSA-2048 Bit
When I open my certificate in console, it shows me this info:
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Which class/method from jsrsasign should I use to get this info?

RSAES OAEP certificate - public key 0 bits

I have a program that create self-sign certificate of RSA algorithm.
The problem is that if I create certificate of RSAES OAEP parameters,
when I open the certificate I see that the size of the public key is 0 bits .
Do anyone know what is the problem?
I already checked that the ASN 1.0 Encoding of the RSA OAEP Pararmeters is ok.
And if I create certificate RSA without OAEP Parameters than the size of the public key is present ok (not as 0 bits).
I checked in the internet and I didn’t find any certificate of RSA with OAEP pararms for example to compare with my certificate.
I will be glad for any suggestion.
This is the certificate in PEM File:
-----BEGIN CERTIFICATE-----
MIIFyzCCA7OgAwIBAgIDMaTyMA0GCSqGSIb3DQEBBAUAMG0xETAPBgNVBAMTCFN0YW0gSXN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3NssBb+2AadRhSvpgP1wkHIVmZ
/VOQN893TdmaS+WQOiocxh2LxJv7QeC8j8fi9k8LTeM4JCqJ0wIDAQABoy8wLTArBgNVHRAE
JDAigA8xOTk4MDEwMTA4MDAwMFqBDzIwMDAwMTAxMDgwMDAyWjANBgkqhkiG9w0BAQQFAAOC
AgEAODPOHhl4J519jEExA2TIwSWLC23lloBQQPJysE0gelbyTv3xGVmJJZF+JAGvxrkvYado
UMPc9pBF57RsB7tznhCHpcYpSRcEIEArZoxfiVkevheLsm9/gyd5RA/oD6xx8WZBFFjHW+fs
urdJPEfR0lBHGmOKBKTa9aeqwJ5Bfi6Rm6/OvbalWBgZh2+5KYhdtMZH7JnsCCR6ZrJzLp8D
uo5M0iIQ/J6D9pDsPBmYK3/P/c7mVhLhjUBtqelkRGO690VzoBykf9MsWE3IT58gq1Av3dGe
J1LSgijha65s/A+l7zEC0fL7UFSXUnNCghEz+PkpcO14wFeg9UIypM0R85IOO0PBg4FVLACT
hmBmFFJCDOCgMwO+xMQZE+eG5gOEUgESHaQfEUoU7JxPHYB/9Xxl2G69nHr2Fx0KuLrjnrym
SgrFubQ3d+XuSTLxr/Lr7gl7EZP68uEsPcw2CXXdpsq4pvmVbrNspfHGn9SimFkEA8qmPqkt
4wiUPCwLkvY+qZ55JnmtPWoeaekJDx7iox0TtiHlQH6Y+/Rl18zU0lITePKPbc5thPZjiwIl
rR5O1PYzlIzE9m/7mFNitIAR2CixJRNiykgz5Q2gjYu4itmb2aHE1UuzK2mORny2gYnG7mdr
dD2y8hDouRCuxND/kkfdDyspGSRQcnqnmpkt7nQ=
-----END CERTIFICATE-----
Public key is 4096 bits long in the attached certificate. Using MD5 hash with 4k keys is very strange combination as MD5 hash is too weak and all strength of 4k key is eliminated by weakness of a hash.