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

  • Home
  • SEARCH
  • 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 8219835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:18:49+00:00 2026-06-07T13:18:49+00:00

I have a database with passwords encrypted in SHA1, I need to convert them

  • 0

I have a database with passwords encrypted in SHA1, I need to convert them to the SHA1 binary form and encode with base64, how can I get that?

This is what I have:

# echo -n "password" | openssl sha1
5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8

This is what I need:

# echo -n "password" | openssl sha1 -binary | base64
W6ph5Mm5Pz8GgiULbPgzG37mj9g=
  • 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-07T13:18:53+00:00Added an answer on June 7, 2026 at 1:18 pm
    require 'digest/sha1'
    require 'base64'
    
    Base64.encode64(Digest::SHA1.digest('password'))
    # => "W6ph5Mm5Pz8GgiULbPgzG37mj9g=\n"
    

    this adds a newline though so you may need to use

    Base64.encode64(Digest::SHA1.digest('password')).chop
    # => "W6ph5Mm5Pz8GgiULbPgzG37mj9g="
    

    or even simpler, as @FrederickCheung suggested:

    Digest::SHA1.base64digest('password')
    

    Edit

    when you only have the hex string of the SHA-1 encoded password, then do

    require 'base64'
    
    pass = "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"
    Base64.encode64([pass].pack('H*')).chop
    # => "W6ph5Mm5Pz8GgiULbPgzG37mj9g="
    

    or you can even bypass the base64 library and solely rely on pack:

    [[pass].pack('H*')].pack('m0')
    # => "W6ph5Mm5Pz8GgiULbPgzG37mj9g="
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database with thousands of md5 encrypted passwords and I need to
How do I compare Encrypted passwords that I inserted in the database from the
I have stored user passwords in an encrypted format in my database. However, now
I have an old database of users which contains passwords hashed in a way
I have this algorithm in Java to store passwords in database. I'd like to
I use NHibernate and have a custom type for encrypting passwords in the database
Unfortunately, I have plaintext passwords in a database. I want to pass these plaintext
I have a postgres database on my localhost I can access without a password
I have a database that contains user details including sensitive data. They're not as
I have passwords for members on a site encrypted using MD5 and stored in

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.