Created
May 9, 2016 16:57
-
-
Save amalagaura/415eaa510b5edd14057353179b809744 to your computer and use it in GitHub Desktop.
.NET passwords operable in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby dotNetHash.rb password123 LU7hUk4MXAvlq6DksvP9SQ== | |
require "base64" | |
require “digest” | |
# Encode password as double-width characters | |
password_as_text = ARGV.first | |
double_width_password = [] | |
double_width_password = password_as_text.encode("UTF-16LE").bytes.to_a | |
# Unencode the salt | |
salt = Base64.decode64(ARGV[1])# Concatenate salt+pass | |
salt_pass_array = [] | |
salt_pass_array = salt.bytes.to_a + double_width_password | |
# Repack array as string and hash it. Then encode. | |
salt_pass_str = salt_pass_array.pack('C*') | |
sha1_saltpass = Digest::SHA1.digest(salt_pass_str) | |
enc_sha1_saltpass = Base64.encode64(sha1_saltpass).strip() | |
puts "Encoded SHA1 saltpass is " + enc_sha1_saltpass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment