以下に示すように、暗号化 – 復号化のシナリオがあります。
//[テキスト ID 文字列を入力としてクリア] -- [(ASCII GetByte) + エンコーディング] -- [バイト配列としての暗号化] -- [データベース列は VarBinary にある] -- [byte[] を VarBinary パラメータとして SP に渡す比較]
//[データベースに VarBinary として保存された ID] -- [バイト配列として読み取る] -- [(バイト配列として復号化) + エンコード + (ASCII Get String)] -- 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;
}