2014-11-17 7 views
2

Windows Phone에서 SHA 256 암호화를 사용하고 싶습니다. 8.1 C# xaml. 그러나 나는 다음과 같은 오류가 점점 오전 : 는Windows Phone 8.1에서 System.Security.Cryptography.SHA256을 찾을 수 없습니다.

모듈가 mscorlib.dll에서 유형 System.Security.Cryptography.HashAlgorithm를 찾을 수 없습니다 그리고 실제로에서는 System.Security.Cryptography는 윈도우 폰 (또는 Windows 8 점)을 사용할 수 없습니다. 그러나 Windows.Security.Cryptography를 사용할 수는 있지만이 클래스도 찾을 수 없습니다.

SHA 256 암호화를 사용해야합니까? 그것에 대한 DLL이 있습니까?

감사합니다.

답변

3

유니버설 앱을 사용하는 경우 조금 더 어려워집니다. 하지만

using Windows.Security.Cryptography; 
using Windows.Security.Cryptography.Core; 

HashAlgorithmProvider hap = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256); 
CryptographicHash ch = hap.CreateHash();    

// read in bytes from file then append with ch.Append(data)   

Windows.Storage.Streams.IBuffer b_hash = ch.GetValueAndReset();  // hash it 
string hash_string = CryptographicBuffer.EncodeToHexString(b_hash); // encode it to a hex string for easy reading 

당신은 HashAlgorithmProvider을 만들어야을 시작하고 그런 다음 당신이를 만들

해시

을 지원하는 모든 HashAlgorithmNames. 네임 스페이스를 참조 사용할 HashAlgorithm로 제공받을 CryptographicHash.

은 그럼 당신은

.Append(data)는 그런 다음 해시를 계산하여 CryptographicHash에 바이트 단위로 추가 할 수 있습니다.

그런 다음 원하는 경우 16 진수 문자열로 인코딩 할 수 있습니다. 뻔뻔 스크린 샷 내 해싱 앱의


:

Click Here for Fullsize Image enter image description here

+0

내 질문에 대답을 위해 시간 내 주셔서 감사합니다. 그래서이 링크의 도움을받을 수 있습니다. http://msdn.microsoft.com/en-us/library/windows.security.cryptography.core.hashalgorithmprovider.aspx?cs-save-lang=1&cs-lang=csharp#code 맞지? – asitis

+0

@asitis 그래, 맞아. 원하는 경우 기본적으로 내 코드를 복사 할 수 있습니다. 버퍼를 채워 넣기 만하면됩니다. 나는 그렇게 해 2GB 이상의 거대한 파일을 쉽게 해싱 할 수있다. –

관련 문제