国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

使用vb.net加密和解密文件。(好象英文靈,中文不靈)

2024-07-10 13:04:16
字體:
來源:轉載
供稿:網友
imports system
imports system.io
imports system.security
imports system.security.cryptography
imports system.text

module encrypt
    private const ssecretkey as string = "password"

    public sub main()
        encryptfile("c:/temp/test.txt", _
                        "c:/temp/encrypted.txt", _
                        ssecretkey)
        decryptfile("c:/temp/encrypted.txt", _
                    "c:/temp/decrypted.txt", _
                    ssecretkey)
    end sub

    sub encryptfile(byval sinputfilename as string, _
                       byval soutputfilename as string, _
                       byval skey as string)

        dim fsinput as new filestream(sinputfilename, _
                                    filemode.open, fileaccess.read)
        dim fsencrypted as new filestream(soutputfilename, _
                                    filemode.create, fileaccess.write)

        dim des as new descryptoserviceprovider()

        '為des算法設置安全碼.
        '必須是64位,8個字節
        des.key = asciiencoding.ascii.getbytes(skey)


        des.iv = asciiencoding.ascii.getbytes(skey)

        '創建des加密碼實例
        dim desencrypt as icryptotransform = des.createencryptor()
        '
        dim cryptostream as new cryptostream(fsencrypted, _
                                            desencrypt, _
                                            cryptostreammode.write)

        '讀取文件到數組
        dim bytearrayinput(fsinput.length - 1) as byte
        fsinput.read(bytearrayinput, 0, bytearrayinput.length)
        '寫到加密文件中
        cryptostream.write(bytearrayinput, 0, bytearrayinput.length)
        cryptostream.close()
    end sub

    sub decryptfile(byval sinputfilename as string, _
        byval soutputfilename as string, _
        byval skey as string)

        dim des as new descryptoserviceprovider()
        des.key() = asciiencoding.ascii.getbytes(skey)
        des.iv = asciiencoding.ascii.getbytes(skey)

        '讀取加密文件
        dim fsread as new filestream(sinputfilename, filemode.open, fileaccess.read)
        '
        dim desdecrypt as icryptotransform = des.createdecryptor()
        '
        dim cryptostreamdecr as new cryptostream(fsread, desdecrypt, cryptostreammode.read)
        '輸出到解密文件
        dim fsdecrypted as new streamwriter(soutputfilename)
        fsdecrypted.write(new streamreader(cryptostreamdecr).readtoend)
        fsdecrypted.flush()
        fsdecrypted.close()
    end sub
end module

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 景谷| 宝坻区| 巴林左旗| 静宁县| 烟台市| 吉安县| 巴林左旗| 双流县| 宣汉县| 交口县| 临颍县| 资兴市| 深圳市| 衡阳县| 梁山县| 长兴县| 永济市| 黑水县| 偏关县| 东乡县| 新竹县| 乌拉特中旗| 永丰县| 海阳市| 南城县| 博兴县| 安福县| 桓台县| 金乡县| 宝鸡市| 沙坪坝区| 建始县| 扶绥县| 琼结县| 汉寿县| 北京市| 莱阳市| 鱼台县| 南平市| 绥滨县| 吐鲁番市|