国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 甘德县| 台北县| 高平市| 澄江县| 思南县| 松滋市| 肃宁县| 雷州市| 台山市| 喀喇沁旗| 宁津县| 洛浦县| 同心县| 天水市| 五原县| 呼图壁县| 马鞍山市| 辰溪县| 常宁市| 通辽市| 宜阳县| 金秀| 大悟县| 聂荣县| 依兰县| 云龙县| 凌源市| 讷河市| 泰顺县| 呼和浩特市| 雷山县| 乌拉特中旗| 沁水县| 治县。| 南漳县| 大余县| 那坡县| 英山县| 雷州市| 荆州市| 增城市|