How to decrypt the number using Javascript

I have a scenario I have a cipher text and RSA private key (encrypted form) along with AES 256 Key. My concern is I want JavaScript code that will first decrypt RSA private key using AES 256 key I don’t have initialization vector(which is randomly generated 16 bit). The decrypted RSA private key is then used to decrypt the main cipher text.
We can decrypt the data with below ruby code but we want to achieve same in Javascript

The ruby code:

require 'openssl'
require 'base64'

private_key_path = 'C:\Users\User\Documents\private3.pem'
passphrase = 'xxxxxxxx' 

begin
  private_key = OpenSSL::PKey::RSA.new(File.read(private_key_path), passphrase)
  encrypted_ssn = File.read('C:\Users\User\Documents\Ruby\input_case.txt')
  decrypted_ssn = private_key.private_decrypt(Base64.decode64(encrypted_ssn))
  puts "Decrypted SSN: #{decrypted_ssn}"
rescue Errno::ENOENT => e
  puts "Error: #{e.message}. Make sure the file paths are correct."
rescue OpenSSL::PKey::RSAError => e
  puts "Error: #{e.message}. Check if the private key or passphrase is correct."
end

Key Formats

Cipher Text Format: rnIlnXweYGYX107Lz7nAIYSASUpZsZoAAUS9zueA=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Private key:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,A7AF3A76C321D9FFFFFFFFFFFFFF

SOj8/nY3qkQKKcpjIXxCSIJey8LVuvYLMeZL+8BRrdnxM1RTNAMLeO3Gd7hD7PLJ
oBRsLmynXYVwIM6l0G1B+KBjXjb1K9iwnyrGFSbA3Fx8LnNaMHnfW+A3+bUUiBt0XXXXXXXXXXXXX…

-----END RSA PRIVATE KEY-----

I hope you’re not attempting to do this through a public interface. Are you doing this in something like Node?

Yes I am using Node.js environment. Can you please with code ???

Well I cant say i’ve done it before myself, certainly without an IV.

Node.js has the crypto module, which handles a lot of functions like this.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.