vb.netdes vbnet的sendkeys

求VB.NET生成TET文件的加密方法

使用加密方式存儲(chǔ)即可實(shí)現(xiàn)別人無(wú)法查看內(nèi)容,加密的方式有很多,適用你這里使用的是可逆的算法,推薦你使用DES加密

創(chuàng)新互聯(lián)專注于延安企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站,商城系統(tǒng)網(wǎng)站開發(fā)。延安網(wǎng)站建設(shè)公司,為延安等地區(qū)提供建站服務(wù)。全流程按需策劃設(shè)計(jì),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

Imports?System ?

Imports?System.Collections.Generic ?

Imports?System.Text ?

Imports?System.IO ?

Imports?System.Security ?

Imports?System.Security.Cryptography ?

Namespace?ZU14 ?

NotInheritable?Public?Class?DES ?

Private?iv?As?String?=?"1234的yzo"?

Private?key?As?String?=?"123在yzo"?

'/?summary?

'/?DES加密偏移量,必須是=8位長(zhǎng)的字符串 ?

'/?/summary?

Public?Property?IV()?As?String ?

Get ?

Return?iv ?

End?Get ?

Set ?

iv?=?value?

End?Set ?

End?Property ?

'/?summary?

'/?DES加密的私鑰,必須是8位長(zhǎng)的字符串 ?

'/?/summary?

Public?Property?Key()?As?String ?

Get ?

Return?key ?

End?Get ?

Set ?

key?=?value?

End?Set ?

End?Property ?

'/?summary?

'/?對(duì)字符串進(jìn)行DES加密 ?

'/?/summary?

'/?param?name="sourceString"待加密的字符串/param?

'/?returns加密后的BASE64編碼的字符串/returns?

Public?Function?Encrypt(sourceString?As?String)?As?String ?

Dim?btKey?As?Byte()?=?Encoding.Default.GetBytes(key) ?

Dim?btIV?As?Byte()?=?Encoding.Default.GetBytes(iv) ?

Dim?des?As?New?DESCryptoServiceProvider() ?

Dim?ms?As?New?MemoryStream() ?

Try ?

Dim?inData?As?Byte()?=?Encoding.Default.GetBytes(sourceString) ?

Try ?

Dim?cs?As?New?CryptoStream(ms,?des.CreateEncryptor(btKey,?btIV),?CryptoStreamMode.Write) ?

Try ?

cs.Write(inData,?0,?inData.Length) ?

cs.FlushFinalBlock() ?

Finally ?

cs.Dispose() ?

End?Try ?

Return?Convert.ToBase64String(ms.ToArray()) ?

Catch ?

End?Try ?

Finally ?

ms.Dispose() ?

End?Try ?

End?Function?'Encrypt ?

'/?summary?

'/?對(duì)DES加密后的字符串進(jìn)行解密 ?

'/?/summary?

'/?param?name="encryptedString"待解密的字符串/param?

'/?returns解密后的字符串/returns?

Public?Function?Decrypt(encryptedString?As?String)?As?String ?

Dim?btKey?As?Byte()?=?Encoding.Default.GetBytes(key) ?

Dim?btIV?As?Byte()?=?Encoding.Default.GetBytes(iv) ?

Dim?des?As?New?DESCryptoServiceProvider() ?

Dim?ms?As?New?MemoryStream() ?

Try ?

Dim?inData?As?Byte()?=?Convert.FromBase64String(encryptedString) ?

Try ?

Dim?cs?As?New?CryptoStream(ms,?des.CreateDecryptor(btKey,?btIV),?CryptoStreamMode.Write) ?

Try ?

cs.Write(inData,?0,?inData.Length) ?

cs.FlushFinalBlock() ?

Finally ?

cs.Dispose() ?

End?Try ?

Return?Encoding.Default.GetString(ms.ToArray()) ?

Catch ?

End?Try ?

Finally ?

ms.Dispose() ?

End?Try ?

End?Function?'Decrypt ?

'/?summary?

'/?對(duì)文件內(nèi)容進(jìn)行DES加密 ?

'/?/summary?

'/?param?name="sourceFile"待加密的文件絕對(duì)路徑/param?

'/?param?name="destFile"加密后的文件保存的絕對(duì)路徑/param?

Overloads?Public?Sub?EncryptFile(sourceFile?As?String,?destFile?As?String) ?

If?Not?File.Exists(sourceFile)?Then ?

Throw?New?FileNotFoundException("指定的文件路徑不存在!",?sourceFile) ?

End?If ?

Dim?btKey?As?Byte()?=?Encoding.Default.GetBytes(key) ?

Dim?btIV?As?Byte()?=?Encoding.Default.GetBytes(iv) ?

Dim?des?As?New?DESCryptoServiceProvider() ?

Dim?btFile?As?Byte()?=?File.ReadAllBytes(sourceFile) ?

Dim?fs?As?New?FileStream(destFile,?FileMode.Create,?FileAccess.Write) ?

Try ?

Try ?

Dim?cs?As?New?CryptoStream(fs,?des.CreateEncryptor(btKey,?btIV),?CryptoStreamMode.Write) ?

Try ?

cs.Write(btFile,?0,?btFile.Length) ?

cs.FlushFinalBlock() ?

Finally ?

cs.Dispose() ?

End?Try ?

Catch ?

Finally ?

fs.Close() ?

End?Try ?

Finally ?

fs.Dispose() ?

End?Try ?

End?Sub?'EncryptFile ?

'/?summary?

'/?對(duì)文件內(nèi)容進(jìn)行DES加密,加密后覆蓋掉原來(lái)的文件 ?

'/?/summary?

'/?param?name="sourceFile"待加密的文件的絕對(duì)路徑/param?

Overloads?Public?Sub?EncryptFile(sourceFile?As?String) ?

EncryptFile(sourceFile,?sourceFile) ?

End?Sub?'EncryptFile ?

'/?summary?

'/?對(duì)文件內(nèi)容進(jìn)行DES解密 ?

'/?/summary?

'/?param?name="sourceFile"待解密的文件絕對(duì)路徑/param?

'/?param?name="destFile"解密后的文件保存的絕對(duì)路徑/param?

Overloads?Public?Sub?DecryptFile(sourceFile?As?String,?destFile?As?String) ?

If?Not?File.Exists(sourceFile)?Then ?

Throw?New?FileNotFoundException("指定的文件路徑不存在!",?sourceFile) ?

End?If ?

Dim?btKey?As?Byte()?=?Encoding.Default.GetBytes(key) ?

Dim?btIV?As?Byte()?=?Encoding.Default.GetBytes(iv) ?

Dim?des?As?New?DESCryptoServiceProvider() ?

Dim?btFile?As?Byte()?=?File.ReadAllBytes(sourceFile) ?

Dim?fs?As?New?FileStream(destFile,?FileMode.Create,?FileAccess.Write) ?

Try ?

Try ?

Dim?cs?As?New?CryptoStream(fs,?des.CreateDecryptor(btKey,?btIV),?CryptoStreamMode.Write) ?

Try ?

cs.Write(btFile,?0,?btFile.Length) ?

cs.FlushFinalBlock() ?

Finally ?

cs.Dispose() ?

End?Try ?

Catch ?

Finally ?

fs.Close() ?

End?Try ?

Finally ?

fs.Dispose() ?

End?Try ?

End?Sub?'DecryptFile ?

'/?summary?

'/?對(duì)文件內(nèi)容進(jìn)行DES解密,加密后覆蓋掉原來(lái)的文件 ?

'/?/summary?

'/?param?name="sourceFile"待解密的文件的絕對(duì)路徑/param?

Overloads?Public?Sub?DecryptFile(sourceFile?As?String) ?

DecryptFile(sourceFile,?sourceFile) ?

End?Sub?'DecryptFile ?

End?Class?'DES ?

End?Namespace?'ZU14?

對(duì)文本文件加密

Dim?des?As?New?ZU14.DES() ?

des.IV?=?"abcd哈哈笑"?

des.Key?=?"必須八位"?

'加密

des.EncryptFile("d:\a.txt",?"d:\b.txt") ?

'解密

des.DecryptFile("d:\b.txt")

用VB.net編寫一個(gè)加密解密軟件

"采用DES算法"這個(gè)說(shuō)法不明確,首先是使用多少位的DES進(jìn)行加密,通常是128位或192位,其次是,要先把主密鑰轉(zhuǎn)化成散列,才能供DES進(jìn)行加密,轉(zhuǎn)化的方法是什么沒(méi)有明確,通常是md5,所以有的銀行卡說(shuō)是128位md5 3DS就是指用md5轉(zhuǎn)換主密鑰散列,用DES進(jìn)行加密,但是DES本身是64位(包含校驗(yàn)碼),2DES是128位,3DES是192位,但是沒(méi)有2DES的叫法,所以128位、192位統(tǒng)稱3DES

要完整的md5+3DS實(shí)例,需要100分以上,要不到我的空間中查找相關(guān)的文章

求VB.NET的MD5算法調(diào)用

下面是完整的類,可以設(shè)置任意密碼

'DES及md5加密解密----添加引用中添加對(duì)system.web的引用。

Imports?System.Security.Cryptography

Imports?System

Imports?System.Text

Imports?System.Web

'''?summary

'''?DES加密類

'''?/summary

'''?remarks/remarks

Public?Class?DESEncrypt

Public?Sub?DESEncrypt()

End?Sub

Public?Shared?Function?Encrypt(ByVal?Text?As?String)?As?String

Return?Encrypt(Text,?"12345678")

End?Function

Public?Shared?Function?Encrypt(ByVal?Text?As?String,?ByVal?sKey?As?String)?As?String

Dim?des?As?New?DESCryptoServiceProvider()

Dim?inputByteArray?As?Byte()

inputByteArray?=?Encoding.Default.GetBytes(Text)

des.Key?=?ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey,?"md5").Substring(0,?8))

des.IV?=?ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey,?"md5").Substring(0,?8))

Dim?ms?As?New?System.IO.MemoryStream()

Dim?cs?As?New?CryptoStream(ms,?des.CreateEncryptor(),?CryptoStreamMode.Write)

cs.Write(inputByteArray,?0,?inputByteArray.Length)

cs.FlushFinalBlock()

Dim?ret?As?New?StringBuilder()

Dim?b?As?Byte

For?Each?b?In?ms.ToArray()

ret.AppendFormat("{0:X2}",?b)

Next

Return?ret.ToString()

End?Function

Public?Shared?Function?Decrypt(ByVal?Text?As?String)?As?String

Return?Decrypt(Text,?"12345678")

End?Function

Public?Shared?Function?Decrypt(ByVal?Text?As?String,?ByVal?sKey?As?String)?As?String

Dim?des?As?New?DESCryptoServiceProvider()

Dim?len?As?Integer

len?=?Text.Length?/?2

Dim?inputByteArray(len?-?1)?As?Byte

Dim?x,?i?As?Integer

For?x?=?0?To?len?-?1

i?=?Convert.ToInt32(Text.Substring(x?*?2,?2),?16)

inputByteArray(x)?=?CType(i,?Byte)

Next

des.Key?=?ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey,?"md5").Substring(0,?8))

des.IV?=?ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey,?"md5").Substring(0,?8))

Dim?ms?As?New?System.IO.MemoryStream()

Dim?cs?As?New?CryptoStream(ms,?des.CreateDecryptor(),?CryptoStreamMode.Write)

cs.Write(inputByteArray,?0,?inputByteArray.Length)

cs.FlushFinalBlock()

Return?Encoding.Default.GetString(ms.ToArray())

End?Function

End?Class

'以下是調(diào)用方法

Public?Class?Form1

Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click?'加密

Dim?str_Encrypt?As?String?=?DESEncrypt.Encrypt("你要加密的文本,可以是任意長(zhǎng)度",?"密碼,可以很長(zhǎng),如果省略這個(gè)參數(shù)就是默認(rèn)的12345678")

End?Sub

Private?Sub?Button2_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button2.Click?'解密

Dim?str_Decrypt?As?String?=?DESEncrypt.Decrypt("你要解密的文本,?可以是任意長(zhǎng)度",?"加密時(shí)用到的密碼,如果省略這個(gè)參數(shù)就是默認(rèn)的12345678")

End?Sub

網(wǎng)站欄目:vb.netdes vbnet的sendkeys
網(wǎng)頁(yè)路徑:http://muchs.cn/article26/docsdcg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、網(wǎng)站維護(hù)、品牌網(wǎng)站建設(shè)、用戶體驗(yàn)、網(wǎng)站設(shè)計(jì)公司網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化