当前位置: 首页>>代码示例>>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;未经允许,请勿转载。