Decrypting using Javascript

Joined
Jun 3, 2023
Messages
5
Reaction score
0
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:🔑: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:🔑: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-----
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top