我必须将一个字符串的哈希总数添加到文件中。哈希总数为SHA-256(Base-64)。
字符串流如下:
Transaction Type|External System Reference Number|Original External System Reference|Account title|SAP Company Number|Payment Currency|Payment Amount|Trade / Posting Date|Settlement Date|Client Account (SAP)|Client Number (SAP)|Benficiarys bank sort code|Beneficiarys bank swift code|Beneficiarys Bank Line 1|Beneficiarys Bank Line 2|Intermediary Bank|Intermediary swift code|FX Rate|Beneficiary Customer|Beneficiary Account Number|Beneficiary’s Bank Country|Resereved for future use|Creation Date / Time|Payment Details|Bank to Bank Info|Payment Charges|Ordering Customer|File Origination Code|Resereved for future use|Charge account|Resereved for future use|Resereved for future use|Resereved for future use
FCYOut|TESTREF000101||A Company Limited|GB0010001|EUR|0000000663.75|20130327|20130402|10000001|90023562||SBZAZAJJXXX|Standard Bank Joburg|Sandton Joburg||||John Smith|1010102356|ZA||20130327163043|Invoice 23B|Branch code 234234|SHA||XXXX|||||
当我使用以下命令进行哈希总计时
echo -n $txt | openssl dgst -binary -sha256 | openssl base64
它给出的价值如下:
SqL7nAwQ/Y+2LXXfLaX25CtfSjoShY9+FCRZp5jcGO0=
但是当我把它发送到另一方时,他们在解密后会得到错误的信息:
他们期望以下示例消息的加密字符串
1EjGezzIXFT+/QvXUuK1juo8rUJGuymRmUnXgA8OzA8=
有人可以帮我解决这里有什么问题吗?我希望价值与其他方输出相同。
答案 0 :(得分:0)
编码为UTF8
且没有行分隔符。这是我用来测试的C#代码:
SHA256 sha = new SHA256Managed();
StringBuilder sbTest = new StringBuilder();
sbTest.Append("Transaction Type|External System Reference Number|Original External System Reference|Account title|SAP Company Number|Payment Currency|Payment Amount|Trade / Posting Date|Settlement Date|Client Account (SAP)|Client Number (SAP)|Benficiarys bank sort code|Beneficiarys bank swift code|Beneficiarys Bank Line 1|Beneficiarys Bank Line 2|Intermediary Bank|Intermediary swift code|FX Rate|Beneficiary Customer|Beneficiary Account Number|Beneficiary’s Bank Country|Resereved for future use|Creation Date / Time|Payment Details|Bank to Bank Info|Payment Charges|Ordering Customer|File Origination Code|Resereved for future use|Charge account|Resereved for future use|Resereved for future use|Resereved for future use");
sbTest.Append("FCYOut|TESTREF000101||A Company Limited|GB0010001|EUR|0000000663.75|20130327|20130402|10000001|90023562||SBZAZAJJXXX|Standard Bank Joburg|Sandton Joburg||||John Smith|1010102356|ZA||20130327163043|Invoice 23B|Branch code 234234|SHA||XXXX|||||");
string str = sbTest.ToString();
byte[] data = sha.ComputeHash(Encoding.UTF8.GetBytes(str));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
string base64String = Convert.ToBase64String(data);
Console.WriteLine(base64String);