We have script written in powershell to get some information from users terminal. And have created SHA1 of that information, just to verify integrity of result.
On server side where we get these information from multiple terminals, we are verifying each results and this side of script is being written in Ruby.
Now problem, is that both these script are giving different SHA1 hash, and I am not sure where I am making mistake.
Powershell code is as given below.
$String = "
Directory: D:\OneDrive -
ControlCase\jt-work\evidance-collection\evidances-text\PCI_Evidences_CCIN-CAS-VKAUS\evidences
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2019-01-16 1:14 PM 7073 21_to_calc_hash.ps1
-a--- 2019-01-16 1:15 PM 9973 CCIN-CAS-VKAUS_pci_evidence_Q21.txt
-a--- 2019-01-15 9:37 PM 67399 CCIN-CAS-VKAUS_pci_evidence_Q23.txt
-a--- 2019-01-15 9:37 PM 5055 CCIN-CAS-VKAUS_pci_evidence_Q34.txt
-a--- 2019-01-15 9:38 PM 10820 CCIN-CAS-VKAUS_pci_evidence_Q45.txt
-a--- 2019-01-15 9:38 PM 13129 CCIN-CAS-VKAUS_pci_evidence_Q50.txt
-a--- 2019-01-15 9:38 PM 7163 CCIN-CAS-VKAUS_pci_evidence_Q67.txt
-a--- 2019-01-15 9:39 PM 4301 CCIN-CAS-VKAUS_pci_evidence_Q69.txt
-a--- 2019-01-15 9:39 PM 2900 CCIN-CAS-VKAUS_pci_evidence_Q81.txt
"
Function Get-Hash([String] $String)
{
$StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create("sha1").ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{
[Void]$StringBuilder.Append($_.ToString("x2"))
}
$StringBuilder.ToString()
}
Get-Hash($String)
and this the hash we get for above script e7c527068445c52635287b9ecf55566c2564d595
below is Ruby script
require 'digest'
varj = "
Directory: D:\OneDrive -
ControlCase\jt-work\evidance-collection\evidances-text\PCI_Evidences_CCIN-CAS-VKAUS\evidences
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2019-01-16 1:14 PM 7073 21_to_calc_hash.ps1
-a--- 2019-01-16 1:15 PM 9973 CCIN-CAS-VKAUS_pci_evidence_Q21.txt
-a--- 2019-01-15 9:37 PM 67399 CCIN-CAS-VKAUS_pci_evidence_Q23.txt
-a--- 2019-01-15 9:37 PM 5055 CCIN-CAS-VKAUS_pci_evidence_Q34.txt
-a--- 2019-01-15 9:38 PM 10820 CCIN-CAS-VKAUS_pci_evidence_Q45.txt
-a--- 2019-01-15 9:38 PM 13129 CCIN-CAS-VKAUS_pci_evidence_Q50.txt
-a--- 2019-01-15 9:38 PM 7163 CCIN-CAS-VKAUS_pci_evidence_Q67.txt
-a--- 2019-01-15 9:39 PM 4301 CCIN-CAS-VKAUS_pci_evidence_Q69.txt
-a--- 2019-01-15 9:39 PM 2900 CCIN-CAS-VKAUS_pci_evidence_Q81.txt
"
varj_Encoded = varj.encode(Encoding::ISO_8859_1)
puts Digest::SHA1.hexdigest(varj_Encoded)
and here is the SHA1 has we get from this script. 77f7cecb2b75c16b1e929a56b644fad7d7f95965
Now condition here is, I can't make/propose any changes in Powershell part. I need to tune ruby code to make it match.