使用加密方式存儲即可實現(xiàn)別人無法查看內(nèi)容,加密的方式有很多,適用你這里使用的是可逆的算法,推薦你使用DES加密
站在用戶的角度思考問題,與客戶深入溝通,找到石阡網(wǎng)站設(shè)計與石阡網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站設(shè)計、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名注冊、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋石阡地區(qū)。
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位長的字符串 ?
'/?/summary?
Public?Property?IV()?As?String ?
Get ?
Return?iv ?
End?Get ?
Set ?
iv?=?value?
End?Set ?
End?Property ?
'/?summary?
'/?DES加密的私鑰,必須是8位長的字符串 ?
'/?/summary?
Public?Property?Key()?As?String ?
Get ?
Return?key ?
End?Get ?
Set ?
key?=?value?
End?Set ?
End?Property ?
'/?summary?
'/?對字符串進行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?
'/?對DES加密后的字符串進行解密 ?
'/?/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?
'/?對文件內(nèi)容進行DES加密 ?
'/?/summary?
'/?param?name="sourceFile"待加密的文件絕對路徑/param?
'/?param?name="destFile"加密后的文件保存的絕對路徑/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?
'/?對文件內(nèi)容進行DES加密,加密后覆蓋掉原來的文件 ?
'/?/summary?
'/?param?name="sourceFile"待加密的文件的絕對路徑/param?
Overloads?Public?Sub?EncryptFile(sourceFile?As?String) ?
EncryptFile(sourceFile,?sourceFile) ?
End?Sub?'EncryptFile ?
'/?summary?
'/?對文件內(nèi)容進行DES解密 ?
'/?/summary?
'/?param?name="sourceFile"待解密的文件絕對路徑/param?
'/?param?name="destFile"解密后的文件保存的絕對路徑/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?
'/?對文件內(nèi)容進行DES解密,加密后覆蓋掉原來的文件 ?
'/?/summary?
'/?param?name="sourceFile"待解密的文件的絕對路徑/param?
Overloads?Public?Sub?DecryptFile(sourceFile?As?String) ?
DecryptFile(sourceFile,?sourceFile) ?
End?Sub?'DecryptFile ?
End?Class?'DES ?
End?Namespace?'ZU14?
對文本文件加密
Dim?des?As?New?ZU14.DES() ?
des.IV?=?"abcd哈哈笑"?
des.Key?=?"必須八位"?
'加密
des.EncryptFile("d:\a.txt",?"d:\b.txt") ?
'解密
des.DecryptFile("d:\b.txt")
先實例化該類
Dim wrapper As New ClassLibrary1.Simple3Des("你的密鑰")
然后
Dim cipherText As String = wrapper.EncryptData("要加密的文本")
或
Dim cipherText As String = wrapper.DecryptData("要揭秘的文本")
我覺得你的并不是RSA加密解密算法。
在.net的有一個System.Security.Cryptography的命名空間,里面有一RSACryptoServiceProvider的類用來對byte進行RSA加密解密。
具體例子如下:
using System;
using System.Security.Cryptography;
using System.Text;
class RSACSPSample
{
static void Main()
{
try
{
//Create a UnicodeEncoder to convert between byte array and string.
UnicodeEncoding ByteConverter = new UnicodeEncoding();
//Create byte arrays to hold original, encrypted, and decrypted data.
byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt");
byte[] encryptedData;
byte[] decryptedData;
//Create a new instance of RSACryptoServiceProvider to generate
//public and private key data.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Pass the data to ENCRYPT, the public key information
//(using RSACryptoServiceProvider.ExportParameters(false),
//and a boolean flag specifying no OAEP padding.
encryptedData = RSAEncrypt(dataToEncrypt,RSA.ExportParameters(false), false);
//Pass the data to DECRYPT, the private key information
//(using RSACryptoServiceProvider.ExportParameters(true),
//and a boolean flag specifying no OAEP padding.
decryptedData = RSADecrypt(encryptedData,RSA.ExportParameters(true), false);
//Display the decrypted plaintext to the console.
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
}
catch(ArgumentNullException)
{
//Catch this exception in case the encryption did
//not succeed.
Console.WriteLine("Encryption failed.");
}
}
static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
{
try
{
//Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Import the RSA Key information. This only needs
//toinclude the public key information.
RSA.ImportParameters(RSAKeyInfo);
//Encrypt the passed byte array and specify OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
return RSA.Encrypt(DataToEncrypt, DoOAEPPadding);
}
//Catch and display a CryptographicException
//to the console.
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
static public byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo,bool DoOAEPPadding)
{
try
{
//Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Import the RSA Key information. This needs
//to include the private key information.
RSA.ImportParameters(RSAKeyInfo);
//Decrypt the passed byte array and specify OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
return RSA.Decrypt(DataToDecrypt, DoOAEPPadding);
}
//Catch and display a CryptographicException
//to the console.
catch(CryptographicException e)
{
Console.WriteLine(e.ToString());
return null;
}
}
}
[Visual Basic]
Try
'Create a new RSACryptoServiceProvider object.
Dim RSA As New RSACryptoServiceProvider()
'Export the key information to an RSAParameters object.
'Pass false to export the public key information or pass
'true to export public and private key information.
Dim RSAParams As RSAParameters = RSA.ExportParameters(False)
Catch e As CryptographicException
'Catch this exception in case the encryption did
'not succeed.
Console.WriteLine(e.Message)
End Try
[C#]
try
{
//Create a new RSACryptoServiceProvider object.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Export the key information to an RSAParameters object.
//Pass false to export the public key information or pass
//true to export public and private key information.
RSAParameters RSAParams = RSA.ExportParameters(false);
}
catch(CryptographicException e)
{
//Catch this exception in case the encryption did
//not succeed.
Console.WriteLine(e.Message);
}
加密有許多的方法。最基礎(chǔ)的一種就是利用對應(yīng)表。
比如我對應(yīng)
A 對 B
B 對 D
C 對 E
D 對 C
┇
┇
然后可以把他存在數(shù)組里,使用時對應(yīng)即可。比如
Dim Mi(25) As String
Mi(0)="B"
Mi(1)="D"
:
:
:
如果要加密文字s$,產(chǎn)生新的字符串r$,就可以
s$=UCase(s$)
For i=1 to Len(s$)
r$=r$+Mi(Asc(Mid(s$,i,1)-64)
Next i
也可以使用Xor法。
Xor(異或)有加/解密的功能。
如果
s=p Xor k
則有
p=s Xor k
k為密鑰。
"采用DES算法"這個說法不明確,首先是使用多少位的DES進行加密,通常是128位或192位,其次是,要先把主密鑰轉(zhuǎn)化成散列,才能供DES進行加密,轉(zhuǎn)化的方法是什么沒有明確,通常是md5,所以有的銀行卡說是128位md5 3DS就是指用md5轉(zhuǎn)換主密鑰散列,用DES進行加密,但是DES本身是64位(包含校驗碼),2DES是128位,3DES是192位,但是沒有2DES的叫法,所以128位、192位統(tǒng)稱3DES
要完整的md5+3DS實例,需要100分以上,要不到我的空間中查找相關(guān)的文章
網(wǎng)頁標題:密鑰加密算法vb.net,公開密鑰算法的加密的密鑰和解密的密鑰
網(wǎng)站地址:http://m.rwnh.cn/article12/dssdhgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、電子商務(wù)、標簽優(yōu)化、品牌網(wǎng)站設(shè)計、移動網(wǎng)站建設(shè)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)