vb.net加密狗方案

野生程序猿-杂烧5年前随意分享817

先前做过e语言加密狗,被识别为病毒。现在 挑战vb.net


对vb.net完全不熟悉,于是面向百度编程。好在加密狗厂家提供了vb.net的demo,我要做的事情就是让其他程序能够调用。


思路就是直接编译成exe,然后其他后端语言exec调用,通过传入参数进行一些密钥计算。主要是研究命令行如何返回数据。

Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Imports System.Text

Module Module1
    Public Const XSKEY_SUCCESS As Integer = &H0 '成功


    Declare Function XSKeyFind Lib "XSKey.dll" (ByRef Count As Integer) As Integer

    Declare Function XSKeyGetHID Lib "XSKey.dll" (ByVal Index As Short, ByRef pHID As Byte) As Integer
    Declare Function XSKeyGetLevel Lib "XSKey.dll" (ByVal Index As Short, ByRef pLevel As Byte) As Integer
    Declare Function XSKeyGetType Lib "XSKey.dll" (ByVal Index As Short, ByRef pType As Byte) As Integer
    Declare Function XSKeyGetVersion Lib "XSKey.dll" (ByVal Index As Short, ByRef pVersion As Byte) As Integer

    Declare Function XSKeySetDeviceName Lib "XSKey.dll" (ByVal Index As Short, ByRef szName As Byte) As Integer
    Declare Function XSKeyGetDeviceName Lib "XSKey.dll" (ByVal Index As Short, ByRef szName As Byte) As Integer
    Declare Function XSKeySetSoftID Lib "XSKey.DLL" (ByVal Index As Short, ByRef pSoftID As Byte) As Integer
    Declare Function XSKeyGetSoftID Lib "XSKey.DLL" (ByVal Index As Short, ByRef pSoftID As Byte) As Integer

    Public Function getstr(ByRef myvalue() As Byte) As String
        'Dim strText As String
        'strText = BitConverter.ToString(myvalue)
        'Return strText

        Return Chr(myvalue(0)) & Chr(myvalue(1)) & Chr(myvalue(2)) & Chr(myvalue(3)) & Chr(myvalue(4)) & Chr(myvalue(5)) & Chr(myvalue(6)) & Chr(myvalue(7))
    End Function




    Public Function time() As Integer
        Dim s As String = DateDiff("s", "1970-01-01 00:00:00", Now)

        Dim n As Integer = CType(s, Integer)
        n = n - 8 * 3600
        Return n
    End Function

    Public Function O0O0OO() As String
        Dim OOO0 As String = Chr(68)
        Dim O0O0 As String = Chr(53)
        Dim O000 As String = Chr(77)


        Return O000 & OOO0 & O0O0
    End Function


    Public Function OO00OO00(ByVal strSource As String) As String
        Dim dataToHash As Byte() = (New System.Text.ASCIIEncoding).GetBytes(strSource)
        Dim hashvalue As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName(O0O0OO()), System.Security.Cryptography.HashAlgorithm).ComputeHash(dataToHash)
        Dim ATR As String = ""
        Dim i As Integer
    
        For i = 0 To 15
            ATR &= Hex(hashvalue(i)).PadLeft(2, "0").ToLower
        Next
     
        Return ATR

    End Function

    Public Function OO00OOOO00(ByVal strSource As String) As String
        Dim l1l1l1ll As String = OO00OO00(strSource)
        l1l1l1ll = l1l1l1ll & "" & OO00OO00(l1l1l1ll & l1l1l1ll)
        Return l1l1l1ll

    End Function

    Public Function ll1111llll(ByVal strSource As String, ByVal strSource2 As String) As String
        Dim l1l1l1ll As String = OO00OO00(strSource & "|" & strSource2)
        l1l1l1ll = OO00OO00(l1l1l1ll)
        Return l1l1l1ll

    End Function

    Sub Main()

        Dim Index As Integer
        Dim Count, retcode As Integer
        Dim HID(16) As Byte
        Dim SoftID(16) As Byte
        Dim Active_Index As Integer

        Dim Hid_check As Integer = 0
        Count = 0
        Index = 0

        Dim shijianchuo As Long
        Dim shijianchuo_key As String
        Dim end_shijianchuo As Long
        Dim end_shijianchuo_str As String
        Dim end_shijianchuo_key As String

        Dim end_shijianchuo_cha As Long

        Dim shijianchuo_OO00OO As String

        Dim active_softid As String
        Dim my_softid As String

        Dim active_keyid As String

        active_softid = ""

        Dim sa() As String = System.Environment.GetCommandLineArgs



        If sa.Length > 2 Then
            my_softid = sa(1)
            end_shijianchuo_str = sa(2)
            end_shijianchuo = CLng(end_shijianchuo_str)
            For Each s As String In sa
                'Console.WriteLine("接收到的参数:" & s & Chr(13))
            Next
        Else
            Console.WriteLine("error-01 | usbkey config err")
            Exit Sub
        End If




        retcode = XSKeyFind(Count)
        If (retcode <> 0) Then
            Console.WriteLine("error-02 | find usbkey  err ")
            Exit Sub
        Else
            ' Console.WriteLine("查找到加密狗个数:" & Count & Chr(13))
        End If


        For i = 0 To Count - 1
            retcode = XSKeyGetSoftID(i, SoftID(0))
            If (retcode = 0) Then
                'Console.WriteLine("获取加密狗硬件ID:" & getstr(SoftID) & "|" & my_softid & Chr(13))
                If (getstr(SoftID) = my_softid) Then
                    Active_Index = i
                    active_softid = my_softid
                End If
            End If
        Next

        '加密狗中没有当前需要的的 直接返回失败
        If (active_softid = "") Then
            Console.WriteLine("error-03 | usbkey softid check err")
            Exit Sub
        Else
            retcode = XSKeyGetHID(Active_Index, HID(0))
            If (retcode <> 0) Then
                Console.WriteLine("error-04 |  find usbkey id  err")
                Exit Sub
            Else

                'active_keyid = getstr(HID)
                'my_keyid 多个里面分割出来,于加密后的active_keyid比较
                'If (ll1111llll(active_softid, active_keyid) <> my_keyid_key Or active_keyid <> my_keyid) Then
                'Console.WriteLine("error-05 |  usbkey key check err")
                ' Exit Sub

            End If
        End If


        shijianchuo = time()
        'Console.WriteLine(shijianchuo & Chr(13))
        'Console.WriteLine(end_shijianchuo & Chr(13))

        shijianchuo_key = shijianchuo & "|" & active_softid
        shijianchuo_key = shijianchuo_key & shijianchuo_key
        shijianchuo_OO00OO = OO00OOOO00(shijianchuo_key)
        Console.WriteLine(shijianchuo & "|" & shijianchuo_OO00OO & Chr(13))

    End Sub

End Module

目前只知道命令行输出返回是 

Console.WriteLine

其他其实不懂,编译也搞了半天。经历了几个坑,其中一个就是.net的版本,最早遇到到客户机器上遇到.net版本不够的情况。稍微瞎捣鼓了几下,设置成.net2.0 这样一般不需要额外安装.net的支持。


标签: 加密狗.net

相关文章

推荐一个前端框架Svelte(超级轻量级)

现在的前端框架太多了,国内用得比较多的是vue,非常强大,但是个人感觉灵活性糟糕,代码比较繁琐。近期接触一个框架,顿时让我感觉非常的爽,一种似曾相似的感觉,这个框架就是Svelte。Svelte是一个...

php对图片进行加密

由于公司辛辛苦苦处理了一些教学素材,怕同行盗取,于是需要对素材中的图片进行加密,稍微防一下吧。大写的O数字0,让破解的人稍微增加一点难度吧。<?php function pic_ji...

再谈面向过程编程,工序再到时序

再谈面向过程编程,工序再到时序

先看一个需求,这个是教学软件的一个环节。进入机场哪些东西能带哪些东西不能带?哪些东西放在行李箱托运?哪些放在包里随身携带?教学软件一般是带有互动的,有时序的概念。1、时序开始,先是导学说话。2、用户开...

取巧快速加水印

收到个紧急需求,由于我们客户主要是学校。我们开发的主要是教学软件,但是也开发教学课件。这次就是交付的教学课件,用在别的系统上。学校提需求需要在课件上加水印。不知道是不是看了钉钉等软件带来的灵感,要斜斜...

开发UI框架:【laylte】Svelte版LAYUI(缓一下,继续钻研一下填填坑)

开发UI框架:【laylte】Svelte版LAYUI(缓一下,继续钻研一下填填坑)

接下来准备做全局的方法了,象弹窗,还是希望尽量做到一句话调用。layui的弹窗组件里有一个tips功能,把我难住了。感觉这个jquery比较容易实现。有这样一个场景,滚动的页面里如果有tips功能,需...

编译的困扰-经验分享

编译的困扰-经验分享

开发的时候我们编译经常遇到坑,一会要用python3,一会又要用python 2.7的情况,nodejs一会要这个版本,一会要那个版本的情况,甚至npm都有版本要求。...