2010-07-19 4 views
3

몇 가지 간단한 암호화/암호 해독 기능을 웹 페이지에 포함시키는 C# .Net 코드를 포함하고 싶습니다. 내부 웹 페이지이므로 사용자는 암묵적으로 신뢰할 수 있습니다. 이 일을 할 수있는 방법이 있습니까? 암호화를 위해 공개 키를 얻기 위해 사용자의 Windows-MY 키 저장소 (CAPI를 통해)를 해독해야하며 LDAP 서버를 누르십시오.Embeded .Net C# 웹 페이지에서?

답변

1

C#을 사용하여 COM 개체를 가짜로 만든 다음 JavaScript를 사용하여 해당 COM 개체를 호출하고 브라우저를 통해 CAPI와 상호 작용할 수있었습니다.

자바 스크립트 :

<html> 
<head> 
<script language="javascript"> 
var keystore = new ActiveXObject("RBCrypto.KeyStore"); 

function getCertList() 
{ 
    try { 
    keystore.openKeyStore("MY", true, false); 
    var size = keystore.getStoreSize(); 

    var list = document.getElementById('list'); 
    list.size = size; 

    for(var i = 0; i < size; i++) 
    { 
     var fname = keystore.getFriendlyName(i, true); 
     var opt = new Option(fname, fname); 
     list.options.add(opt); 
    } 
    } 
    catch(err) 
    { 
    alert(err.description); 
    } 
} 
</script> 
</head> 
<body onload="getCertList()"> 
    <center> 
    <h2>KeyStore Test</h2> 
    <hr /> 
    <br /> 
    <select id="list"></select> 
    </center> 
</body> 
</html> 

C 번호 :

using System; 
using System.Runtime.InteropServices; 
using System.Security; 
using System.Security.Cryptography; 
using System.Security.Cryptography.X509Certificates; 

namespace RBCrypto 
{ 
    public interface AXInterface 
    { 
     void openKeyStore(string storeName, bool currentUser, bool readOnly); 
     int getStoreSize(); 
     string getFriendlyName(int index, bool subjectNameIfEmpty); 
    } 

    [ClassInterface(ClassInterfaceType.AutoDual)] 
    public class KeyStore :AXInterface 
    { 
     public void openKeyStore(string storeName, bool currentUser, bool readOnly) 
     { 
      if (keystoreInitialized) 
       throw new Exception("Key Store must be closed before re-initialization"); 

      try 
      { 
       if (currentUser) //user wants to open store used by the current user 
        certificateStore = new X509Store(storeName, StoreLocation.CurrentUser); 
       else    //user wants to open store used by local machine 
        certificateStore = new X509Store(storeName, StoreLocation.LocalMachine); 

       if (readOnly) 
        certificateStore.Open(OpenFlags.ReadOnly); 
       else 
        certificateStore.Open(OpenFlags.ReadWrite); 

       allCertificates = certificateStore.Certificates; 

       if (allCertificates == null) 
       { 
        certificateStore.Close(); 
        throw new NullReferenceException("Certificates could not be gathered"); 
       } 

       keystoreInitialized = true; 
      } 
      catch (ArgumentException ae) 
      { 
       throw ae; 
      } 
      catch (SecurityException se) 
      { 
       throw se; 
      } 
      catch (CryptographicException ce) 
      { 
       throw ce; 
      } 
      catch (NullReferenceException ne) 
      { 
       throw ne; 
      } 
     } 

     .... 
    } 
} 

C# 어셈블리 정보 :

이 자신의 컴퓨터에 당신의 .DLL을 isntall하는 사용자를했다 작동하기 위해서는
// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components. If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type. 
[assembly: ComVisible(true)] 

(.dll을 설치 프로그램에 vsdraCOM으로 등록하도록 지정했는지 확인하십시오.) 사이트를 truste에 추가해야합니다. d 사이트.

4

Silverlight를 사용할 수 있습니다. 당신은뿐만 아니라 자바 스크립트에서 암호화를 할 수 있지만

참고 : Script# 같은 자바 스크립트 컴파일러

+0

이미 사용자의 Windows-MY 키 저장소에있는 키와 Sivelight 또는 Javascript에서 읽을 수없는 키를 사용하고 싶습니다. –

+0

@Petey : 그러면 브라우저 플러그인을 작성해야합니다. – SLaks

+0

SLaks에 감사드립니다 (Ex Lax에서 플레이해야할까요?), 브라우저 플러그인에 대한 정보를 어디에서 찾아야합니까? –

4

"웹 페이지에 넣기"란 의미를 정의 하시겠습니까? 웹 페이지는 일반적으로 Javascript (및 Java) 만 알고있는 브라우저에서 실행됩니다.

당신은 Silverlight 응용 프로그램으로 할 수 있습니다.

+0

Silverlight에는 필요한 암호화 기능이 없습니다.내가 찾은 Windows-MY 키 저장소에 접근 할 방법이 없다면? –

1

암호화/암호 해독 논리가 응용 프로그램 내에있는 새 ASP.NET 응용 프로그램을 작성하는 것이 좋습니다. 아마도 이러한 요청을 처리하기위한 전용 페이지가있는 새로운 webforms 응용 프로그램을 만들 수 있습니다.

암호화 논리를 별도의 .NET 어셈블리에 작성한 다음 ASP.NET 응용 프로그램에서이 어셈블리를 참조하는 것이 좋습니다.

서비스로 사용하려는 것인지 또는 사용자가 텍스트 상자에 텍스트를 입력하고 방문시 암호화를 수행하는지 여부는 명확하지 않습니다.

+0

이 작업을 수행 할 수 있지만 Windows-MY 키 저장소에서 암호 해독을 위해 사용자의 개인 키를 가져 오는 방법이 필요합니다. 다른 모든 것은 서버 측에서 할 수 있습니다. –

0

AJAX를 사용하여 네트워크에서 사용한 암호화 기능을 호출 할 수 있습니다.