我有一个加密 - 解密方案,如下所示。
//[明文ID字符串作为输入]--[(ASCII GetByte)+编码]--[作为字节数组加密]--[数据库列在VarBinary中]--[将字节[]作为VarBinary参数传递给SP比较]
//[ID在数据库中存储为VarBinary]--[读取为字节数组]--[(解密为字节数组)+编码+(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;
}