teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

文法の修正

2021/11/01 15:50

投稿

tehori
tehori

スコア1

title CHANGED
File without changes
body CHANGED
@@ -28,23 +28,23 @@
28
28
  {
29
29
 
30
30
  Sample sample = new Sample();
31
- Console.WriteLine(sample.DecS("RYlIxh5X8ktRsFuquVPeFiP2qP","wns the ow"));
31
+ Console.WriteLine(sample.Decode("...","aaa"));
32
32
 
33
33
 
34
34
  }
35
35
 
36
- private string DecS(string text, string p)
36
+ private string Decode(string text, string p)
37
37
  {
38
- System.Security.Cryptography.RijndaelManaged _rijndeal = new System.Security.Cryptography.RijndaelManaged();
38
+ System.Security.Cryptography.RijndaelManaged _rijndael = new System.Security.Cryptography.RijndaelManaged();
39
39
 
40
40
  byte[] _key, _iv;
41
- GenerateKeyFromPassWord(p, _rijndeal.KeySize, out _key, _rijndeal.BlockSize, out _iv);
41
+ GenerateKeyFromPassWord(p, _rijndael.KeySize, out _key, _rijndael.BlockSize, out _iv);
42
- _rijndeal.Key = _key;
42
+ _rijndael.Key = _key;
43
- _rijndeal.IV = _iv;
43
+ _rijndael.IV = _iv;
44
44
 
45
45
  byte[] _strByte = System.Convert.FromBase64String(text);
46
46
 
47
- System.Security.Cryptography.ICryptoTransform _decryptor = _rijndeal.CreateDecryptor();
47
+ System.Security.Cryptography.ICryptoTransform _decryptor = _rijndael.CreateDecryptor();
48
48
 
49
49
  byte[] _decByte = _decryptor.TransformFinalBlock(_strByte, 0, _strByte.Length);
50
50
  _decryptor.Dispose();
@@ -52,15 +52,14 @@
52
52
  return System.Text.Encoding.UTF8.GetString(_decByte);
53
53
  }
54
54
 
55
- public static void GenerateKeyFromPassWord(string pass, int keySize, out byte[] key, int blockSize, out byte[] iv)
55
+ public static void GKFP(string pass, int keySize, out byte[] key, int blockSize, out byte[] iv)
56
56
  {
57
- byte[] _salt = System.Text.Encoding.UTF8.GetBytes("これがsaltとなります");
57
+ byte[] _salt = System.Text.Encoding.UTF8.GetBytes("・・・");
58
58
 
59
- System.Security.Cryptography.Rfc2898DeriveBytes _deviceBytes = new System.Security.Cryptography.Rfc2898DeriveBytes(pass, _salt);
59
+ System.Security.Cryptography.Rfc2898DeriveBytes _deviceBytes = new System.Security.Cryptography.Rfc2898DeriveBytes(password, _salt);
60
- _deviceBytes.IterationCount = 1000;
60
+
61
-
62
- key = _deviceBytes.GetBytes(keySize / 8);
61
+ key = _deviceBytes.GetBytes(keySize);
63
- iv = _deviceBytes.GetBytes(blockSize / 8);
62
+ iv = _deviceBytes.GetBytes(blockSize);
64
63
  }
65
64
  }
66
65
  }