What Is CAPICOM?
CAPICOM is a Microsoft® ActiveX® control that provides a COM interface to Microsoft CryptoAPI. It exposes a select set of CryptoAPI functions to enable application developers to easily incorporate digital signing and encryption functionality into their applications. Because it uses COM, application developers can access this functionality in a number of programming environments such as Microsoft® Visual Basic®, Visual Basic Script, Active Server Pages, Microsoft® JScript®, C++, and others. CAPICOM is packaged as an ActiveX control, allowing Web developers to utilize it in Web based applications as well.
Where To Get It
CAPICOM is available today for download from the MSDN Web site. CAPICOM is delivered with the Platform SDK and is redistributable free of charge. The Platform SDK contains CAPICOM samples, API documentation, and the redistributable CAPICOM ActiveX control. The Platform SDK can be downloaded from the following URL:
http://www.microsoft.com/en-us/download/details.aspx?id=25281
예제1
출처 : http://yungun.net/64
function MD5(strString)
dim cp
set cp = Server.CreateObject("CAPICOM.HashedData")
cp.Algorithm = 3
cp.Hash Ustr2Bstr(strString) 'Unicode string -> Byte String Conversion
MD5 = cp.Value
set cp = nothing
end function
function UStr2Bstr(UStr)
'Unicode string to Byte string conversion
Dim lngLoop
Dim strChar
dim strResult
strResult = ""
For lngLoop = 1 to Len(UStr)
strChar = Mid(UStr, lngLoop, 1)
strResult = strResult & ChrB(AscB(strChar))
Next
UStr2Bstr = strResult
end function
원하는 알고리즘에 따라 아래 상수를 적용하면 됩니다.
Const CAPICOM_HASH_ALGORITHM_SHA1 = 0
Const CAPICOM_HASH_ALGORITHM_MD2 = 1
Const CAPICOM_HASH_ALGORITHM_MD4 = 2
Const CAPICOM_HASH_ALGORITHM_MD5 = 3
Const CAPICOM_HASH_ALGORITHM_SHA256 = 4
Const CAPICOM_HASH_ALGORITHM_SHA384 = 5
Const CAPICOM_HASH_ALGORITHM_SHA512 = 6
strEncoded = cp.Base64Encode(strString)
strDecoded = cp.Base64Decode(strString)
set cp = nothing
예제 2
출처 : http://blog.naver.com/PostView.nhn?blogId=tick0000&logNo=50092768556
<%
Const CAPICOM_ENCRYPTION_ALGORITHM_3DES = 3
Const gcKEY = "ABCDEFG"
Public Function Encrypt(Message)
Dim ed, key
key = gcKEY
Set ed = CreateObject("CAPICOM.EncryptedData")
ed.Content = Message
ed.SetSecret key
Encrypt = ed.Encrypt
Set ed = Nothing
End Function
Public Function Decrypt(EncMessage)
Dim ed, key
key = gcKEY
Set ed = CreateObject("CAPICOM.EncryptedData")
ed.SetSecret key
ed.Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_3DES
ed.Decrypt(EncMessage)
Decrypt = ed.Content
Set ed = Nothing
End Function
...
%>
'쓸만한 주저리' 카테고리의 다른 글
ZeroClipboard 예제 (0) | 2014.02.13 |
---|---|
크롬을 쓰는데 휠을 돌리면 확대/축소가 될 때 (0) | 2014.01.24 |
html tidy (0) | 2013.11.01 |
계절의 기상학적 정의 (0) | 2013.09.28 |
서울택시를 탔는데 카드기가 고장이면? (0) | 2013.08.12 |