我有一个加密 - 解密方案,如下所示。
// [清除文本ID字符串作为输入] - [(ASCII GetByte)+编码] - [编码为字节数组] - [数据库列在VarBinary中] - [将byte []作为VarBinary参数传递到SP进行比较]
// [在数据库中存储为VarBinary的ID] - [读取为字节数组] - [(解密为字节数组)+编码+(ASCII获取字符串)] - 在UI中显示为字符串
我的问题在于解密方案。解密后我得到一个字节数组。之后我正在进行编码(IBM037)。这是对的吗? 上面显示的流程有什么问题吗?
private static byte[] GetEncryptedID(string id)
{
Interface_Request input = new Interface_Request();
input.RequestText = Encodeto64(id);
input.RequestType = Encryption;
ProgramInterface inputRequest = new ProgramInterface();
inputRequest.Test_Trial_Request = input;
using (KTestService operation = new KTestService())
{
return ((operation.KTrialOperation(inputRequest)).Test_Trial_Response.ResponseText);
}
}
private static string GetDecryptedID(byte[] id)
{
Interface_Request input = new Interface_Request();
input.RequestText = id;
input.RequestType = Decryption;
ProgramInterface request = new ProgramInterface();
request.Test_Trial_Request = input;
using (KTestService operationD = new KTestService())
{
ProgramInterface1 response = operationD.KI014Operation(request);
byte[] decryptedValue = response.ICSF_AES_Response.ResponseText;
Encoding sourceByteFormat = Encoding.GetEncoding("IBM037");
Encoding destinationByteFormat = Encoding.ASCII;
//Convert from one byte format to other (IBM to ASCII)
byte[] ibmEncodedBytes = Encoding.Convert(sourceByteFormat, destinationByteFormat,decryptedValue);
return System.Text.ASCIIEncoding.ASCII.GetString(ibmEncodedBytes);
}
}
private static byte[] EncodeTo64(string toEncode)
{
byte[] dataInBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
Encoding destinationByteFormat = Encoding.GetEncoding("IBM037");
Encoding sourceByteFormat = Encoding.ASCII;
//Convert from one byte format to other (ASCII to IBM)
byte[] asciiBytes = Encoding.Convert(sourceByteFormat, destinationByteFormat, dataInBytes);
return asciiBytes;
}
答案 0 :(得分:0)
我找到了答案 - 解密过程,解密后我将IBM037字节转换为ASCII字节。这就是为什么有编码进来。我已经更新了问题中的代码(有更多的解释变量)