Lm th? no ?: G?i a Visual Basic.Th vi?n NET h?ng t? Visual Basic cho cc ?ng d?ng trong Microsoft Office

D?ch tiu ? D?ch tiu ?
ID c?a bi: 317535 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

S? d?ng ny h?ng d?n t?ng b?c ? g?i m?t.NET l?p th vi?n t? Visual Basic cho cc ?ng d?ng. M?u ny cho th?y lm th? no m?t Visual Basic cho Chng tr?nh ?ng d?ng c th? s? d?ng m?t Visual Basic.Th vi?n NET l?p ? m? ha v gi?i m? m?t chu?i. B?n c th? s? d?ng khng gian tn m?t m? h?c, bao g?m trong cc.NET Khun kh?, ? m? ha/gi?i m?.

T?o Visual Basic.NET l?p th vi?n

  1. B?t ?u Microsoft Visual Studio.NET. Trn cc Tp tr?nh n, i?m ?n M?i, sau b?m D an. D?i Visual Basic d? n, ch?n Th vi?n l?p. Tn l?p CryptoClass v nh?p vo Ok. Class1 ?c t?o ra theo m?c ?nh.
  2. Thay th? cc n?i dung c?a Class1 v?i o?n m? sau:

    Imports System.Security.Cryptography
    
    <ComClass(Class1.ClassId, Class1.InterfaceId, Class1.EventsId)> Public Class Class1
        Public Const ClassId As String = "98349785-8BE2-4604-848D-F5B103D61715"
        Public Const InterfaceId As String = "36613EE9-125F-493d-9968-771E18C2226A"
        Public Const EventsId As String = "A036F02F-F87E-4548-A536-7DD7EA8E62B5"
    
        Const sKey As String = "MyKey"
    
        Public Function EncryptTripleDES(ByVal sIn As String) As String
            Dim DES As New TripleDESCryptoServiceProvider()
            Dim hashMD5 As New MD5CryptoServiceProvider()
    
            ' Compute the MD5 hash.
            DES.Key = hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(sKey))
            ' Set the cipher mode.
            DES.Mode = CipherMode.ECB
            ' Create the encryptor.
            Dim DESEncrypt As ICryptoTransform = DES.CreateEncryptor()
            ' Get a byte array of the string.
            Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(sIn)
            ' Transform and return the string.
            Return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
        End Function
    
        Public Function DecryptTripleDES(ByVal sOut As String) As String
            Dim DES As New TripleDESCryptoServiceProvider()
            Dim hashMD5 As New MD5CryptoServiceProvider()
    
            ' Compute the MD5 hash.
            DES.Key = hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(sKey))
            ' Set the cipher mode.
            DES.Mode = CipherMode.ECB
            ' Create the decryptor.
            Dim DESDecrypt As ICryptoTransform = DES.CreateDecryptor()
            Dim Buffer As Byte() = Convert.FromBase64String(sOut)
            ' Transform and return the string.
            Return System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
        End Function
    End Class
    						

    Chu y B?n c th? s? d?ng cc my pht i?n GUID ? t?o m?i GUIDs cho cc ClassId, InterfaceId v EventsId. ? t?o m?i GUIDs, nh?p vo T?o ra GUID trn cc Cng cu tr?nh n.
  3. T? Thu?c tnh d? n, ch?n C?u h?nh thu?c tnh. Nh?p vo Xy d?ng v sau ch?n cc ng k? cho COM Interoph?p ki?m. Nh?p vo Ok.
  4. Trn cc Xy d?ng tr?nh n, nh?p vo Xy d?ng gi?i php ? t?o ra DLL.

T?o m?t Visual Basic cho cc ?ng d?ng Macro ? g?i l.NET l?p th vi?n

  1. B?t ?u Microsoft Excel. Nh?n ALT + F11 ? b?t ?u Visual Basic Editor.
  2. Trn cc Chn tr?nh n, nh?p vo M-un ? chn m?t m-un ? tr?ng.
  3. Trn cc Cng cu tr?nh n, nh?p vo Tham khao. Thm m?t tham chi?u ?n cc CryptoClass th vi?n v nh?p vo Ok.
  4. G? hay dn o?n m? sau trong m? Module1 c?a s?:
    Sub TestCrypto()
      Dim oCrypto As New CryptoClass.Class1
      Dim sCrypt As String
      
      sCrypt = oCrypto.EncryptTripleDES("This is a test")
      MsgBox "Encrypted text = " & sCrypt
      MsgBox "Decrypted text = " & oCrypto.DecryptTripleDES(sCrypt)
    End Sub
    					

Ki?m tra m?

  1. Trn cc Cng cu tr?nh n, nh?p vo Macro. Trong danh sch macro, nh?p vo TestCrypto, sau b?m Ch?y.
  2. N?u m?t h?p thng i?p s? xu?t hi?n ang hi?n cc chu?i ?c m? ha, Nh?p vo Ok. M?t h?p th th? hai xu?t hi?n ang hi?n cc gi?i m? chu?i.
  3. N?u th vi?n l?p h?c c?n ph?i ?c ng k? ngy khc my tnh ang ch?y.NET Framework, sao chp t?p DLL h? th?ng v ch?y cc l?nh sau y:
    regasm CryptoClass.dll /tlb:CryptoClass.tlb

THAM KH?O

bit thm thng tin, bm vao s bai vit sau xem bai vit trong C s Kin thc Microsoft:
301070Lm th? no ?: M? ha v gi?i m? m?t t?p tin b?ng cch s? d?ng Visual Basic.NET
? bi?t thm chi ti?t, xem Microsoft sau y Trang Web c?a nh pht tri?n m?ng (MSDN):
http://msdn2.Microsoft.com/en-US/Library/aa188489 (office.10) .aspx

Thu?c tnh

ID c?a bi: 317535 - L?n xem xt sau cng: 27 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft Office Access 2003
  • Microsoft Access 2002 Standard Edition
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Office PowerPoint 2003
  • Microsoft PowerPoint 2002 Standard Edition
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • Microsoft Word 2002 Standard Edition
  • Microsoft Visual Studio .NET 2002 Professional Edition
T? kha:
kbcrypt kbsecurity kbhowtomaster kbmt KB317535 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:317535

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com