2011-02-11 2 views
0

동일한 도메인의 다른 사용자 계정에서 실행중인 다른 asp.net 응용 프로그램이 암호를 해독하는 중요한 데이터를 암호화하는 asp.net 응용 프로그램을 작성하고 있습니다.DPAPI를 사용하는 보안 Crypto 키

DPAPI를 사용하여 키 관리를 OS 수준에 전달하라는 많은 기사를 읽었습니다.

이 시나리오에서는 어떻게 DPAPI를 사용할 수 있습니까? 나는 파일이나 데이터베이스에 암호 키를 저장하고 싶지 않다. 당신이 여기서하고있는 것은

Imports System.Security.Cryptography 

' .... 

Dim sensitiveDataBytes() As Byte = Encoding.Unicode.GetBytes(sensitiveData) 
Dim entropy As Byte() = Guid.NewGuid().ToByteArray() 
Dim encryptedSensitiveDataBytes() As Byte = ProtectedData.Protect(sensitiveDataBytes, entropy, DataProtectionScope.LocalMachine) 
Dim entropyPlusSensitiveData As Byte() = entropy.Concat(encryptedSensitiveDataBytes).ToArray() 

Return entropyPlusSensitiveData 

당신이 System.Security.Cryptography.ProtectedData을 사용하고 있습니다 :

답변

0

당신은 System.Security를 ​​참조하고,이 (가 VB.NET입니다하지만 C 번호를 하찮게 이식의) 비슷한 코드가 필요 DPAPI를 사용하여 "로컬 컴퓨터"범위로 데이터를 보호 한 다음 임의의 16 바이트 엔트로피를 생성하여 암호화 된 데이터 앞에 추가합니다. 그런 다음 16+ (암호화 된 데이터의 길이) 크기의 배열을 안전하게 전달할 수 있습니다. 당신이 16 엔트로피 바이트를 제거하고 그 암호를 해독하기 위해 DPAPI를 사용 : 암호 해독 측면에서

당신은 비슷한 트릭을 할

Dim entropyPlusSensitiveData As Byte() = data ' the byte array created previously 
Dim entropy() As Byte = entropyPlusSensitiveData.Take(16).ToArray() 
Dim encryptedSensitiveDataBytes() As Byte = entropyPlusSensitiveData.Skip(16).ToArray() 
Dim sensitiveDataBytes() As Byte = ProtectedData.Unprotect(encryptedSensitiveDataBytes, entropy, DataProtectionScope.LocalMachine) 

엔트로피가 엄격하게 필요하지 않습니다, 그러나 그것은 매우 좋습니다.

관련 문제