當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET DSACryptoServiceProvider.SignData方法代碼示例

本文整理匯總了VB.NET中System.Security.Cryptography.DSACryptoServiceProvider.SignData方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET DSACryptoServiceProvider.SignData方法的具體用法?VB.NET DSACryptoServiceProvider.SignData怎麽用?VB.NET DSACryptoServiceProvider.SignData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了DSACryptoServiceProvider.SignData方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: DSASign

' 導入命名空間
Imports System
Imports System.IO
Imports System.Security.Cryptography
Imports System.Text

Public Class DSASign
    
    Public Shared Sub Main(ByVal CmdArgs() As String)
        If CmdArgs.Length <> 3 Then
            Console.WriteLine("usage: DSASign <key xml> <data> <sign>")
            End
        End If

        Dim xkey As String = LoadString(CmdArgs(0))
        
        
        
        Dim fs As FileStream = File.OpenRead(CmdArgs(1))
        Dim dsa As DSACryptoServiceProvider = New DSACryptoServiceProvider
        dsa.FromXmlString(xkey)
        Dim sig() As Byte = dsa.SignData(fs)
        fs.Close()
        SaveString(CmdArgs(2), Convert.ToString(sig))
        Console.WriteLine("Signature in {0}} file", CmdArgs(2))
    End Sub

    Shared Public Sub SaveString(ByVal fname As String, ByVal data As String)
        Dim datas() As Byte = (New ASCIIEncoding).GetBytes(data)

        Dim fs As FileStream = File.OpenWrite(fname)
        fs.SetLength(0)
        fs.Write(datas, 0, datas.Length)
        fs.Close()

    End Sub
    
    Shared Public Function LoadString(ByVal fname As String) As String
        Dim finfo As FileInfo = New FileInfo(fname)
        Dim length As String = CType(finfo.Length, String)
        Dim buf() As Byte = New Byte(length) {}
        Dim fs As FileStream = File.OpenRead(fname)
        fs.Read(buf, 0, buf.Length)
        fs.Close()

        Return (New ASCIIEncoding).GetString(buf)
    End Function

End Class
開發者ID:VB程序員,項目名稱:System.Security.Cryptography,代碼行數:49,代碼來源:DSACryptoServiceProvider.SignData


注:本文中的System.Security.Cryptography.DSACryptoServiceProvider.SignData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。