2017-05-02 4 views
0

내가 구현 한 AES 알고리즘을 표시하는 표시되지 않습니다. 값을 암호화 한 후 https://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged(v=vs.110).aspx 메시지 상자가이 웹 사이트를 사용하여 암호 해독 데이터

는 문자열로 변환되어 데이터베이스로 전송됩니다. 그것은 성공적이었다. Encrypted 값을 검색 할 때 성공했습니다. 그러나 암호 해독을 시작할 때 오류가 발견되지 않았고 출력도 표시되지 않았습니다 (메시지 상자를 사용하여 출력 받기). 나는 어떻게해야합니까?

byte[] cipherbytes = System.Text.ASCIIEncoding.Default.GetBytes(encypted); 
     //AES Decryption start 
     try 
     { 
      using (AesManaged myAes = new AesManaged()) 
      { 
       // Decrypt the bytes to a string. 
       string roundtrip = DecryptStringFromBytes_Aes(cipherbytes, myAes.Key, myAes.IV); 
       //Console.WriteLine("Round Trip: {0}", roundtrip); 
       MessageBox.Show(roundtrip, "Decrypted text"); //this meessage box is not showing 
      } 

     } 
     catch (Exception e) 
     { 
      Console.WriteLine("Error: {0}", e.Message); 
      //MessageBox.Show("Inside is working"); 
     } 

// 여기에

static string DecryptStringFromBytes_Aes(byte[] cipherText, byte[] Key, byte[] IV) 
    { 
     // Check arguments. 
     if (cipherText == null || cipherText.Length <= 0) 
      throw new ArgumentNullException("cipherText"); 
     if (Key == null || Key.Length <= 0) 
      throw new ArgumentNullException("Key"); 
     if (IV == null || IV.Length <= 0) 
      throw new ArgumentNullException("IV"); 

     // Declare the string used to hold 
     // the decrypted text. 
     string plaintext = null; 

     // Create an AesManaged object 
     // with the specified key and IV. 
     using (AesManaged aesAlg = new AesManaged()) 
     { 
      aesAlg.Key = Key; 
      aesAlg.IV = IV; 

      // Create a decrytor to perform the stream transform. 
      ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); 

      // Create the streams used for decryption. 
      using (MemoryStream msDecrypt = new MemoryStream(cipherText)) 
      { 
       using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) 
       { 
        using (StreamReader srDecrypt = new StreamReader(csDecrypt)) 
        { 

         // Read the decrypted bytes from the decrypting stream 
         // and place them in a string. 
         plaintext = srDecrypt.ReadToEnd(); 
        } 
       } 
      } 

     } 

답변

0

귀하의 DecryptStringFromBytes_Aes 값을 반환하지 않습니다, 당신은 마지막에 return plaintext;을 추가해야합니다뿐만 아니라 암호 해독 알고리즘이다. 그것은 컴파일합니까?

메시지 박스

그것은합니다 ( DecryptStringFromBytes_Aes 기능에서) 예외 이전 코드는 데, 그 라인에 도착하지 않습니다 ... 때문에 표시되지 않습니다. 이 라인 Console.WriteLine("Error: {0}", e.Message);에 중단 점을 넣고 오류를 확인하십시오. 당신은 또한 작성된 오류에 대한 콘솔을 checl 수 있습니다.

+0

리턴 일반 텍스트; 불행히도 실종되었다. 나는 위의 방법을 사용하여 문제를 찾아 내려고 노력했다. 나는 당신의 제안에 따라 브레이크 포인트를 놓았다. 그러나 아무 일도 일어나지 않았습니다. catch (Exception e), 메시지 상자 팝업에서 Messagbox를 사용할 때. 예외가 발생하고 있음을 보여줍니다. 콘솔 오류를 사용하여 문제를 찾을 수 없습니다. –