Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8038147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:08:19+00:00 2026-06-05T03:08:19+00:00

I have a file with encrypted credentials with RC4, The piece of code in

  • 0

I have a file with encrypted credentials with RC4,
The piece of code in charge to write such credentials to the file is the following:

sub dummyFunction() {
    # Useless stuff for the scope of the problem
    # ...
    my $dbHost = "localhost";
    my $passphrase = "123"; # For example purposes, logic is different.
    my $cipher = Crypt::RC4->new($passphrase);
    return unpack('H*',$cipher->RC4($dbHost));
}

So that piece of code would return something like: 3F9FDCE3891C6B8851
but if I try the following:

sub anotherDummyFunction() {
    my $ciphered_text = &dummyFunction();
    my $passphrase = "123";
    my $cipher = Crypt::RC4->new($passphrase);
    print $cipher->RC4(pack('H*',$ciphered_text));
}

I am expecting to see localhost but instead, I get a bunch of bytes, so how would I get back the original text?

I already checked with a RC4 decryptor online, with my passphrase and my hex encoded string and the RC4 decryptor online does return localhost so I am sure that the encrypted string is right.

Thanks!

P.S.: The above example works in an isolated environment, but when it comes to my script it doesn’t. I cannot get back the original string.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:08:20+00:00Added an answer on June 5, 2026 at 3:08 am

    If anyone encounters this again:

    If you have something like:


    TEST.PL


     #!/usr/bin/perl
     use strict;
     use warnings;
     use Crypt::RC4;
    
     my $cipher = Crypt::RC4->new("passphrase123");
     print unpack('H*',$cipher->RC4("encrypt-me"))."\n";
     print unpack('H*',$cipher->RC4("encrypt-me"))."\n";
    

    You will notice that you’ll end up with two different encoded strings:

     ./test.pl
     25d2aa557cccc3951074
     1e87a5db7830a0b1cabd
    

    In order to avoid this behavior I did:

    undef $cipher

    Right before trying to encrypt another string, and then instantiated the object again.

    If you try this:

     my $cipher = Crypt::RC4->new("passphrase123");
     print unpack('H*',$cipher->RC4("encrypt-me"))."\n";
     undef($cipher);
     $cipher = Crypt::RC4->new("passphrase123");
     print unpack('H*',$cipher->RC4("encrypt-me"))."\n";
    

    You’ll get the same string:

    ./test.pl
    25d2aa557cccc3951074
    25d2aa557cccc3951074
    

    this can also be wrapped in subprocedure, to avoid defining and undefining the object over and over.

    sub encryptString()
    {
        my ($string,$passphrase) = @_;
        my $cipher = Crypt::RC4->new($passphrase);
        return unpack('H*',$cipher->RC4($string));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file encrypted using the following code in c: unsigned char ckey[]
I have code that reads encrypted credentials from a text file. I updated that
I have a file that was encrypted using AES. I use the following NSData
Let's say I have an encrypted file on an iPhone and every time I
I have a pgp-encrypted file that I need to extract data from at runtime.
In my applications web.config file I have a connection string stored. I encrypted it
I have a file encrypted with java application using AES. I also have a
I have an encrypted word/excel/pdf file locally stored which I need to preview in
I have encrypted video file and while decrypting it i have defined Byte byte[]
If I have an encrypted file that is encrypted with AES CBC, would changing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.