###実現したいこととトラブル
C#で復号プログラムを作ろうとしています。
Unhandled Exception:以下のメッセージが調べても理解できず、お力をお貸しいただけませんでしょうか
BASE64形式のテキストに変換する必要があるのでしょうか?
###エラーメッセージ
Unhandled Exception:
System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
at System.Convert.FromBase64CharPtr (System.Char* inputPtr, System.Int32 inputLength) [0x00068] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at System.Convert.FromBase64String (System.String s) [0x00028] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at Sample.Sample.DecS (System.String text, System.String p) [0x0002c] in /workspace/Main.cs:25
at Sample.Sample.Main () [0x00012] in /workspace/Main.cs:11
[ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
at System.Convert.FromBase64CharPtr (System.Char* inputPtr, System.Int32 inputLength) [0x00068] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at System.Convert.FromBase64String (System.String s) [0x00028] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
at Sample.Sample.DecS (System.String text, System.String p) [0x0002c] in /workspace/Main.cs:25
at Sample.Sample.Main () [0x00012] in /workspace/Main.cs:11
###コード
C#
1using System; 2 3namespace Sample 4{ 5 class Sample 6 { 7 static void Main() 8 { 9 10 Sample sample = new Sample(); 11 Console.WriteLine(sample.Decode("...","aaa")); 12 13 14 } 15 16 private string Decode(string text, string p) 17 { 18 System.Security.Cryptography.RijndaelManaged _rijndael = new System.Security.Cryptography.RijndaelManaged(); 19 20 byte[] _key, _iv; 21 GenerateKeyFromPassWord(p, _rijndael.KeySize, out _key, _rijndael.BlockSize, out _iv); 22 _rijndael.Key = _key; 23 _rijndael.IV = _iv; 24 25 byte[] _strByte = System.Convert.FromBase64String(text); 26 27 System.Security.Cryptography.ICryptoTransform _decryptor = _rijndael.CreateDecryptor(); 28 29 byte[] _decByte = _decryptor.TransformFinalBlock(_strByte, 0, _strByte.Length); 30 _decryptor.Dispose(); 31 32 return System.Text.Encoding.UTF8.GetString(_decByte); 33 } 34 35 public static void GKFP(string pass, int keySize, out byte[] key, int blockSize, out byte[] iv) 36 { 37 byte[] _salt = System.Text.Encoding.UTF8.GetBytes("・・・"); 38 39 System.Security.Cryptography.Rfc2898DeriveBytes _deviceBytes = new System.Security.Cryptography.Rfc2898DeriveBytes(password, _salt); 40 41 key = _deviceBytes.GetBytes(keySize); 42 iv = _deviceBytes.GetBytes(blockSize); 43 } 44 } 45}
回答1件
あなたの回答
tips
プレビュー