2014-01-11 6 views
-1

아래의 코드에서 IV 키를 생성하지 않아도되는 이유를 이해하려고합니다. 코드에서이다 :이 샘플 코드를 참조Rijndael 암호화 키

http://msdn.microsoft.com/en-us/library/sb7w85t6(v=vs.85).aspx

Dim key As RijndaelManaged = Nothing 

Try 
    ' Create a new Rijndael key. 
    key = New RijndaelManaged() 

하지만 manaually 두 키를 생성하도록 요구?

Class RijndaelExample 

    Public Shared Sub Main() 
     Try 

      Dim original As String = "Here is some data to encrypt!" 

      ' Create a new instance of the RijndaelManaged 
      ' class. This generates a new key and initialization 
      ' vector (IV). 
      Using myRijndael As New RijndaelManaged() 

       myRijndael.GenerateKey() 
       myRijndael.GenerateIV() 

http://msdn.microsoft.com/en-us/library/System.Security.Cryptography.RijndaelManaged(v=vs.110).aspx이 또한 내가 실제로이 저장 어떻게 ... 소스에 키를 (나는 그것이 가장 안전하지 알고) 하드 코딩 할 계획 .. :

코드에서이다 그것은 응용 프로그램이 열려있을 때마다 새로운 키를 생성하는 것처럼 보입니다.

답변

0

당신이 옳을 때, 당신이 달릴 때마다 새로운 키와 IV가 만들어집니다. 대신, 해시 직접 작성해야한다 - '예를 들어

, 당신으로

SymmetricAlgorithm m_encryption; 
    RSACryptoServiceProvider m_rsa; 
    Rfc2898DeriveBytes m_hash; 

    string password = "Pa55w0rd"; 
    string salt = "this is my salt. There are many like it, but this one is mine."; 

    public void SetupEncryption() 
    { 


     m_encryption = new RijndaelManaged(); 
     m_hash = new Rfc2898DeriveBytes(password, Encoding.ASCII.GetBytes(salt)); 

     m_encryption.Key = m_hash.GetBytes(m_encryption.KeySize/8); 
     m_encryption.IV = m_hash.GetBytes(m_encryption.BlockSize/8); 

    } 

(데이터를 암호화하는 데 사용되며, 비밀번호와 "소금"에서 파생 http://en.wikipedia.org/wiki/Salt_(cryptography) 참조) 소금과 암호를 저장하는 것은 매우 나쁜 형태입니다! 이것은 시작하는 방법을 보여주는 예일뿐입니다. 원칙을 완전히 이해할 때까지 위키피디아와 다른 기사를 통해 잘 살펴보십시오!

관련 문제