当前位置:首页 » 密码管理 » net代码加密

net代码加密

发布时间: 2022-04-01 12:23:06

㈠ .NET如何实现数据加密

http://www.microsoft.com/china/technet/security/guidance/secmod39.mspx(最好的理论资料)
建立一个win form程序,然后把代码拷到后台,即可实现C#非对称加密程序 。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
using System.Security.Cryptography;

namespace 非对称加密
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.SaveFileDialog save;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.RichTextBox richtext2;
private System.Windows.Forms.OpenFileDialog open;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.RichTextBox richtext3;
private System.Windows.Forms.RichTextBox richtext;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
/// <summary>
/// 必需的设计器变量。
private static RSACryptoServiceProvider crypt;
private static string privatekey;
private static string publickey;
private static byte [] bytes;
private static string publicinfo;
private static string privateinfo;
private static string readpublickey;
private static string readprivatekey;
// ///private static byte [] onebytes ;

/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.button6 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.richtext = new System.Windows.Forms.RichTextBox();
this.button1 = new System.Windows.Forms.Button();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.button8 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.richtext3 = new System.Windows.Forms.RichTextBox();
this.label2 = new System.Windows.Forms.Label();
this.richtext2 = new System.Windows.Forms.RichTextBox();
this.button5 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.save = new System.Windows.Forms.SaveFileDialog();
this.open = new System.Windows.Forms.OpenFileDialog();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(32, 64);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(416, 280);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.button6);
this.tabPage1.Controls.Add(this.button3);
this.tabPage1.Controls.Add(this.button2);
this.tabPage1.Controls.Add(this.richtext);
this.tabPage1.Controls.Add(this.button1);
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(408, 255);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "得到钥匙";
//
// button6
//
this.button6.Location = new System.Drawing.Point(72, 168);
this.button6.Name = "button6";
this.button6.TabIndex = 4;
this.button6.Text = "写入文件";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(200, 16);
this.button3.Name = "button3";
this.button3.TabIndex = 3;
this.button3.Text = "保存私匙";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(128, 16);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "保存公钥";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// richtext
//
this.richtext.Location = new System.Drawing.Point(16, 56);
this.richtext.Name = "richtext";
this.richtext.Size = new System.Drawing.Size(256, 96);
this.richtext.TabIndex = 1;
this.richtext.Text = "richTextBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 16);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 23);
this.button1.TabIndex = 0;
this.button1.Text = "得到钥匙信息";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// tabPage2
//
this.tabPage2.Controls.Add(this.button8);
this.tabPage2.Controls.Add(this.button7);
this.tabPage2.Controls.Add(this.label3);
this.tabPage2.Controls.Add(this.richtext3);
this.tabPage2.Controls.Add(this.label2);
this.tabPage2.Controls.Add(this.richtext2);
this.tabPage2.Controls.Add(this.button5);
this.tabPage2.Controls.Add(this.button4);
this.tabPage2.Controls.Add(this.textBox1);
this.tabPage2.Controls.Add(this.label1);
this.tabPage2.Location = new System.Drawing.Point(4, 21);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(408, 255);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "加密解密文字";
//
// button8
//
this.button8.Location = new System.Drawing.Point(216, 72);
this.button8.Name = "button8";
this.button8.TabIndex = 9;
this.button8.Text = "读取私匙";
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// button7
//
this.button7.Location = new System.Drawing.Point(56, 72);
this.button7.Name = "button7";
this.button7.TabIndex = 8;
this.button7.Text = "读取公匙";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(200, 120);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(100, 16);
this.label3.TabIndex = 7;
this.label3.Text = "解密结果";
//
// richtext3
//
this.richtext3.Location = new System.Drawing.Point(200, 144);
this.richtext3.Name = "richtext3";
this.richtext3.Size = new System.Drawing.Size(120, 72);
this.richtext3.TabIndex = 6;
this.richtext3.Text = "richTextBox2";
//
// label2
//
this.label2.Location = new System.Drawing.Point(48, 120);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(128, 16);
this.label2.TabIndex = 5;
this.label2.Text = "加密窗口:";
//
// richtext2
//
this.richtext2.Location = new System.Drawing.Point(40, 144);
this.richtext2.Name = "richtext2";
this.richtext2.Size = new System.Drawing.Size(120, 72);
this.richtext2.TabIndex = 4;
this.richtext2.Text = "richTextBox2";
//
// button5
//
this.button5.Location = new System.Drawing.Point(200, 96);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(112, 23);
this.button5.TabIndex = 3;
this.button5.Text = "使用私匙解密";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(48, 96);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(96, 23);
this.button4.TabIndex = 2;
this.button4.Text = "使用公匙加密";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(104, 32);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(168, 32);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// label1
//
this.label1.Location = new System.Drawing.Point(128, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 16);
this.label1.TabIndex = 0;
this.label1.Text = "请输入加密的文字";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(504, 357);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Form1";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
//得到钥匙信息
private void button1_Click(object sender, System.EventArgs e)
{
crypt=new RSACryptoServiceProvider();
publickey=crypt.ToXmlString(false);
richtext.Text="导出秘匙的情况下:\n"+publickey+"\n";
privatekey=crypt.ToXmlString(true);
string info="仅仅导出公匙的情况下:\n"+privatekey+"\n";
richtext.AppendText(info);
crypt.Clear();

}
//保存公匙信息
private void button2_Click(object sender, System.EventArgs e)
{

save=new SaveFileDialog();
save.Filter="File Text (*.txt)|*.txt|All File (*.*)|*.*";
save.ShowDialog();
publicinfo=save.FileName;

}
//保存密匙信息
private void button3_Click(object sender, System.EventArgs e)
{
save=new SaveFileDialog();
save.Filter="File Text (*.txt)|*.txt|All File (*.*)|*.*";
save.ShowDialog();
privateinfo=save.FileName;

}
//把钥匙信息写入文件
private void button6_Click(object sender, System.EventArgs e)
{

StreamWriter one=new StreamWriter(publicinfo,true,UTF8Encoding.UTF8);
one.Write(publickey);
StreamWriter two=new StreamWriter(privateinfo,true,UTF8Encoding.UTF8);
two.Write(privatekey);
one.Flush();
two.Flush();
one.Close();
two.Close();
MessageBox.Show("成功保存公匙和密匙!");

}
//用公匙加密
private void button4_Click(object sender, System.EventArgs e)
{

crypt=new RSACryptoServiceProvider();
UTF8Encoding enc=new UTF8Encoding();
bytes=enc.GetBytes(textBox1.Text);
crypt.FromXmlString( readpublickey );
bytes = crypt.Encrypt( bytes,false );
string encryttext=enc.GetString(bytes);//encryptbyte);
richtext2.Text="加密结果:\n"+encryttext+"\n"+"加密结束!";
}

private void button5_Click(object sender, System.EventArgs e)
{

UTF8Encoding enc=new UTF8Encoding();
byte [] decryptbyte;
crypt.FromXmlString ( readprivatekey ) ;
decryptbyte = crypt.Decrypt( bytes,false );
string decrypttext=enc.GetString( decryptbyte );
richtext3.Text = "解密结果:\n" + decrypttext + "\n" + "解密结束!" ;

}
//从文件中读取公匙信息
private void button7_Click(object sender, System.EventArgs e)
{
StreamReader sr ;
open = new OpenFileDialog( );
open.Filter="Text File (*.txt)|*.txt|All File (*.*)|*.* ";
// open.ShowDialog();
if(open.ShowDialog()==DialogResult.OK)
{
sr = new StreamReader(open.FileName,UTF8Encoding.UTF8);
}
else
{
MessageBox.Show("发生错误!");
return;
}
readpublickey = sr.ReadToEnd();
sr.Close();
}
//从文件中读取私匙信息
private void button8_Click(object sender, System.EventArgs e)
{
open = new OpenFileDialog( );
open.Filter="Text File (*.txt)|*.txt|All File (*.*)|*.* ";
open.ShowDialog();
StreamReader sr = new StreamReader(open.FileName,UTF8Encoding.UTF8);
readprivatekey = sr.ReadToEnd();
sr.Close();
}

}
}

㈡ net程序加密C#开发软件的源代码怎么加密

一般的加密,通过反编译和跟踪程序运行都不难破解,所以不仅要加密,还要阻止编译,防范跟踪。这是很专业的,市场上有很多现成加密狗产品,可以方便地解决这个问题。源代码只能采取保密措施,加密是不行的。

㈢ 在ASP.Net中,如何使用混淆加密的方法保护自己的源代码

其实,保护代码不需要那么费心。
像.net其实就是把cs文件转换成dll
文件就可以了,转换的方法看帮助或者去网站上搜索一下就能得到你想要的结果。
现在我们很多写的东西,到现在好没有到保密的程度,现在写的东西都是很一般的...除非你写的东西,是考虑到安全的因素很多那么就需要多加考虑一下了...

㈣ .net软件加密,加密锁哪种比较好,混淆代码可以实现吗

加密锁:威步(WIBU)的CodeMeter,AxProtector(for.net)两款软件加密锁性能非常不错 混淆的问题,与传统的代码混淆工具(Obfuscator)不同,AxProtector可以完全阻止对.NET 程序集(由 C#, VB.NET, Delphi.NET, ASP.Net… 等语言编写)的反编译。通俗的讲,AxProtector在破解者和您的 .NET 代码之间构建了强大的防破解保护屏障,生成一个基于 Windows 的而不是基于 MSIL 的兼容格式文件。原始的 .NET 代码完整的被加密后封装在本地代码内,无论何时都不会释放到硬盘,对于破解者是不可见的。 与单纯的.net加密软件不同,AxProtector与CodeMeter硬件加密狗配套餐使用,采用了更为严密的密钥管理,及最先进的AES、RSA、ECC等加密算法存储或传输密钥,保证通讯安全。 .Net代码编译后生成的 .class 中包含有源代码中的所有信息(不包括注释),尤其是在其中保存有调试信息的时候。所以一个按照正常方式编译的.class 文件可以非常轻易地被反编译。一般软件开发商会采用一种叫做混淆器的工具。混淆器的作用是对编译好的代码进行混淆,使得其无法被反编译或者反编译后的代码混乱难懂。由于混淆器只是混淆了方法名称或流程,而不能防止源代码被反编译,因此混淆器的作用只是增加了反编译的难度,最终的结果也是治标不治本。对于一些掌握工具的人来说几乎还是透明的。AxProtector是一款真正意义的加密源代码、防止反编译的.net软件加密软件。 AxProtector加密了.net原代码,任何时候原代码都不可能被还原到硬盘当中。采用AxProtector加密后的.net代码只有在程序调用或执行某一段函数的时候,才能通过AxProtectorClass在内存中解密后返回到程序中执行,运行之后迅速立即加密。这种随机加密、按需解密原代码的功能,能很好的防止.Net程序的反编译,同时能够很好地防止API加密点被摘除。有效地保证了源代码的执行效率和安全性。

㈤ .net软件,加密,哪种加密锁比较好,混淆代码能力如何

《web虎-加密防盗版系统》
团队核心成员平均超10年相关经验,web虎超3年研发测试。近600家软件/课件客户,国家汉办等用户多年实用检验。使用不同于同类产品的驱动层加密使加密锁安全性,通用性更好。
联系我们可以根据您的需求进行免费的试用!

㈥ asp.net(VB)加密解密源代码

答案如下 (经本人测试,肯定是可以用的……)
'-----------------------------------------
' 随机选8个字节既为密钥也为初始向量
Private Shared KEY_64() As Byte = {42, 162, 39, 156, 78, 4, 218, 32}
Private Shared IV_64() As Byte = {55, 113, 346, 79, 36, 99, 167, 3}

'------------------------------------------------
'标准的DES加密
Public Function Encrypt(ByVal value As String) As String
If value <> "" Then
Dim cryptoProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider
Dim ms As MemoryStream = New MemoryStream
Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64), CryptoStreamMode.Write)
Dim sw As StreamWriter = New StreamWriter(cs)
sw.Write(value)
sw.Flush()
cs.FlushFinalBlock()
ms.Flush()
'--------------------------------------
'再转换为一个字符串
Return Convert.ToBase64String(ms.GetBuffer(), 0, ms.Length)
Else
Return ""
End If
End Function
'----------------------------------
'标准的DES解密
Public Function Decrypt(ByVal value As String) As String
If value <> "" Then
Dim cryptoProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider

'---------------------------------------
'从字符串转换为字节组
Dim buffer As Byte() = Convert.FromBase64String(value)
Dim ms As MemoryStream = New MemoryStream(buffer)
Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateDecryptor(KEY_64, IV_64), CryptoStreamMode.Read)
Dim sr As StreamReader = New StreamReader(cs)
Return sr.ReadToEnd()
Else
Return ""
End If
End Function

㈦ 怎么给asp.net的代码加密呀,也就是说怎么保护.aspx的源程序.

asp.net不需要加密,
它的程序会自动编译成DLL。
aspx页面只是页面部分,真正的程序在.VB OR .cs文件中。
编译后就不需要这些文件啊。

㈧ .net软件,用什么软件加密狗加密,能防止代码反编译

.Net软件
特点,
些强
编译工具
.Net
执行文件进行反编译操作,并
相应
IL代码甚至
源代码
即使
采用混淆工具
及强命名工具

根本
解决问题,代码依
容易
Reflectoer等工具反编译源代码
软件加密狗:威步(WIBU)
CodeMeter,AxProtector(for.net)两款软件加密狗性能非

反编译
问题,与传统
代码混淆工具(Obfuscator)
同,AxProtector
完全阻止
.NET
程序集(由
C#,
VB.NET,
Delphi.NET,
ASP.Net…
等语言编写)
反编译
通俗
讲,AxProtector
破解者

.NET
代码
间构建

防破解保护屏障,
基于
Windows
基于
MSIL
兼容格式文件
原始
.NET
代码完整
加密
封装

代码内,
论何

释放
硬盘,
于破解者

与单纯
.net加密软件
同,AxProtector与CodeMeter硬件加密狗配套餐使用,采用

严密
密钥管理,及
先进
AES、RSA、ECC等加密算
存储或传输密钥,保证通讯安全
.Net代码编译
.class
包含
源代码

信息(
包括注释),尤其

保存
调试信息


按照
式编译
.class
文件

轻易
反编译
般软件
发商
采用
种叫做混淆器
工具
混淆器
作用
编译
代码进行混淆,使

反编译或者反编译
代码混乱难懂
由于混淆器
混淆
名称或流程,
能防止源代码
反编译,
混淆器
作用
增加
反编译
难度,


治标
治本

些掌握工具
说几乎
透明
AxProtector
款真
意义
加密源代码、防止反编译
.net软件加密软件
AxProtector加密
.net原代码,任何
候原代码都


硬盘
采用AxProtector加密
.net代码
程序调用或执行某
段函数
候,才能通
AxProtectorClass
内存
解密

程序
执行,运行
迅速立即加密
种随机加密、按需解密原代码
功能,能
防止.Net程序
反编译,同
能够
防止API加密点
摘除

保证
源代码
执行效率
安全性

㈨ asp.net 地址加密,具体的代码

自定义方法来实现URL的加密与解密,代码如下:
using System.Security.Cryptography;
using System.IO;
using System.text;
/// <summary>
/// 加密
/// </summary>
/// <param name="str"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string Encode(string str, string key)
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));
byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(str);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);
stream2.Write(bytes, 0, bytes.Length);
stream2.FlushFinalBlock();
StringBuilder builder = new StringBuilder();
foreach (byte num in stream.ToArray())
{
builder.AppendFormat("{0:X2}", num);
}
stream.Close();
return builder.ToString();
}
/// <summary>
/// Des 解密 GB2312
/// </summary>
/// <param name="str">Desc string</param>
/// <param name="key">Key ,必须为8位 </param>
/// <returns></returns>
public static string Decode(string str, string key)
{
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));
byte[] buffer = new byte[str.Length / 2];
for (int i = 0; i < (str.Length / 2); i++)
{
int num2 = Convert.ToInt32(str.Substring(i * 2, 2), 0x10);
buffer[i] = (byte)num2;
}
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
stream.Close();
return Encoding.GetEncoding("GB2312").GetString(stream.ToArray());
}
首页 → 网站编程 → Asp.Net编程教程 → ASP.NET实现URL加密与解密ASP.NET实现URL加密与解密
时间:2009-8-25 16:13:18 来源:hi..com 作者:webmaster
-
-

调用方法
/// <summary>
/// If don't input key , Use default key
/// Des 加密 GB2312 :
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Encode(string str)
{
return VerifyTool.Encode(str, "Rainight");
}
/// <summary>
/// 解密
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Decode(string str)
{
return VerifyTool.Decode(str, "Rainight");
}

㈩ asp.net如何进行用户名和密码的加密和解密

直接给代码吧
using System.Web.Security;
string str= FormsAuthentication.(TextBox1.text, "MD5")
把TextBox1里的内容用MD5加密返回给str

MD5为不可逆加密所以不可解密,你只有再次加密与加密后的密码匹配来判断是否正确

热点内容
dns服务器怎么看 发布:2025-05-15 22:17:27 浏览:149
3dm的压缩包 发布:2025-05-15 22:09:23 浏览:661
和存储字长 发布:2025-05-15 21:54:09 浏览:514
用什么写c语言 发布:2025-05-15 21:35:56 浏览:418
linux读取u盘 发布:2025-05-15 21:32:13 浏览:508
c语言dos 发布:2025-05-15 21:18:17 浏览:664
sci编译英文 发布:2025-05-15 21:16:57 浏览:383
大猫如何设置密码 发布:2025-05-15 21:15:32 浏览:765
什么叫苹果版的和安卓版的手机 发布:2025-05-15 21:05:18 浏览:254
编程找点 发布:2025-05-15 20:43:10 浏览:588