📄 symmetricwrite.aspx
字号:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<script language="C#" runat=server>
const string DESKey = "ABCDEFGH";
const string DESIV = "HGFEDCBA";
byte[] Convert2ByteArray(string strInput)
{
int intCounter;
char[] arrChar;
arrChar = strInput.ToCharArray();
byte[] arrByte = new byte[arrChar.Length];
for (intCounter=0; intCounter <= arrByte.Length-1; intCounter++)
arrByte[intCounter] = Convert.ToByte(arrChar[intCounter]);
return arrByte;
}
void Button_Click( object s, EventArgs e ) {
byte[] arrDESKey;
byte[] arrDESIV;
byte[] arrInput;
FileStream objFileStream;
DESCryptoServiceProvider objDES;
ICryptoTransform objEncryptor;
CryptoStream objCryptoStream;
arrDESKey = Convert2ByteArray( DESKey );
arrDESIV = Convert2ByteArray( DESIV );
arrInput = Convert2ByteArray( txtInput.Text );
objDES = new DESCryptoServiceProvider();
objEncryptor = objDES.CreateEncryptor( arrDESKey, arrDESIV );
objFileStream = new FileStream( MapPath( "secret.txt" ), FileMode.Create, FileAccess.Write );
objCryptoStream = new CryptoStream( objFileStream, objEncryptor, CryptoStreamMode.Write );
objCryptoStream.Write( arrInput, 0, arrInput.Length );
objCryptoStream.Close();
}
</Script>
<html>
<head><title>SymmetricWrite.aspx</title></head>
<body>
<form Runat="Server">
<h2>DES Encryption</h2>
<b>Enter text to encrypt:</b>
<br>
<asp:TextBox
id="txtInput"
TextMode="Multiline"
Columns="50"
Rows="10"
Runat="Server" />
<p>
<asp:Button
Text="Encrypt!"
OnClick="Button_Click"
Runat="Server" />
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -