1

I have a requirement where I need to do Encryption of my Private Key using Public Key(provided by third party) with RSA/ECB/PKCS1 Encryption

The Public Key is already Padded.

I am generating the private key using cl_sec_sxml_writer=>generate_key( cl_sec_sxml_writer=>co_aes256_algorithm_pem ). Is this the correct way to generate a new key or we can have any random string as a private key?

This private key will be used to encrypt a data string using AES/ECB/PKCS7 padding encryption and then convert to BASE64 and send it via API call. For AES/ECB/PKCS7 padding, I am using the classes provided by following https://github.com/Sumu-Ning/AES. pfb implementation below:

CALL METHOD zcl_aes_utility=>encrypt_xstring
  EXPORTING
    i_key = lv_xstr
    i_data = lv_pwd_xstr
  * i_initialization_vector =
    i_padding_standard = zcl_byte_padding_utility=>MC_PADDING_STANDARD_PKCS_7
    i_encryption_mode = zcl_aes_utility=>mc_encryption_mode_ecb
  IMPORTING
    e_data = lv_encrypt

My query is , how do I encrypt the private key using public key and RSA/ECB/PKCS1 Encryption.

The public key is of length 399 chars and something like this

DfP4hVgyXMSNWJFWakwo44p1PMyRKSmFG+UGq

I have checked other blogs that asks to use standard fm SSF_KRN_ENVELOPE but I am not able to understand how to use it.

Please help. Let me know in case of any further details required.

Philipp
  • 67,764
  • 9
  • 118
  • 153
Naitik
  • 49
  • 10
  • `and then convert to BASE64` if you still thinking how to implement that part, [consider this class](https://stackoverflow.com/a/57366630/911419) – Suncatcher Dec 01 '20 at 11:50
  • "or we can have any random string as a private key"; Generally not because it needs to be not only random but cryptographically secure random. Using a dedicated method should be ok. – koks der drache Dec 02 '20 at 07:29
  • "How do I encrypt the private key using public key and RSA/ECB/PKCS1 Encryption?" I don*t know what you searched for and what your aiming for but encrypting your private key is not different from encrypting any other secret. So maybe you can boil your question down to: "How do I encrypt an xstring for a given base64 RSA public key?" – koks der drache Dec 02 '20 at 07:34

0 Answers0