How to Encrypt Privatekey with another Publickey?

Viewed 167

I have service that runs in background, manages cryptographic keys. I want to transfer those keys from one end to another.

This transfer includes RSA's Private Key also. During this transfer I encrypt actual Key value with some other public key. AES "key value" encryption working as expected. But RSA private key transfer it throws following error.

error=crypto/rsa: message too long for RSA public key size

I understand that only limited amount of bytes can be encrypted by particular length of key length.

For 3072 bit public key it shows, "Data must not be longer than 373 bytes"

For 4096 bit public key it shows, "Data must not be longer than 501 bytes"

Reference -> https://www.devglan.com/online-tools/rsa-encryption-decryption

But in my case, actual key length of private key is 1624(2048 key length). To encrypt this I need to create key pair with 15360 encrypt key with public key(15360)and it is working.

But I've key supported length up to 15360 in my service. So again to transfer this length of private key I need to create again 115200(i'm not sure about this length) of length keypair? Whether this approach is correct or there is any other way for this problem ?

0 Answers
Related