-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhash-password.rb
executable file
·57 lines (51 loc) · 1.72 KB
/
hash-password.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env ruby
#
# Generate a password hash for the Accounts table of SolarWinds Orion
# Copyright (C) 2018 Atredis Partners. MIT License
#
require 'openssl'
require 'base64'
require 'digest'
def usage
$stderr.puts "#{$0} <username> <password>"
exit(1)
end
username = ARGV.shift || usage()
password = ARGV.shift || usage()
padding = "1244352345234"
salt = username.downcase
if salt.length < 8
salt = salt + padding[0, 8-salt.length]
end
pbkdf2 = OpenSSL::PKCS5.pbkdf2_hmac_sha1(password, salt, 1000, 1024)
sha512 = [ Digest::SHA2.new(512).digest(pbkdf2) ].pack("m*").gsub(/\s+/, '')
$stdout.puts "User '#{username}' with password '#{password}' has hash '#{sha512}'"
=begin
# Extract from SolarWinds.Orion.Core.Common.dll HashPassword()
public static string HashPassword(string password, string salt, bool caseSensitive)
{
if (password == null)
{
throw new ArgumentException("password");
}
if (salt == null)
{
throw new ArgumentException("salt");
}
HashAlgorithm hashAlgorithm = new SHA512CryptoServiceProvider();
string password2 = password;
if (!caseSensitive)
{
password2 = password.ToUpperInvariant();
}
Encoding encoding = new UTF8Encoding();
int length = salt.ToLowerInvariant().Length;
byte[] bytes = encoding.GetBytes(salt.ToLowerInvariant() + ((length < 8) ? "1244352345234".Substring(0, 8 - length) : ""));
string result;
using (DeriveBytes deriveBytesAlgorithm = EncryptionHelper.GetDeriveBytesAlgorithm(password2, bytes))
{
result = Convert.ToBase64String(hashAlgorithm.ComputeHash(deriveBytesAlgorithm.GetBytes(EncryptionHelper.BytesUsedForHash)));
}
return result;
}
=end