====求一段加密的代码。谢谢!=====

bestfuture 2007-01-23 01:51:31
如:我取出来机器硬盘的序列号后,通过加密,生成注册码。请一段加密的代码。不要用md5这种的。
...全文
191 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
三碗猪脚 2008-12-21
  • 打赏
  • 举报
回复
mark~~~~~~~~~~
gjunyu1982 2007-01-23
  • 打赏
  • 举报
回复
msdn里面有一个rsa的例子
xiaoyan21 2007-01-23
  • 打赏
  • 举报
回复
可以通过 "异或" 操作来进行加密解密
//content:要加密要解密的字符串
//key:加密或解密的密钥
private string CryptString(string content,string key)
{
int i;
byte[] str = Encoding.Default.GetBytes(content);
byte[] m_key = Encoding.Default.GetBytes(key);

for(i=0;i<str.Length;i++)
{
str[i] ^= m_key[i%m_key.Length];
}

return Encoding.Default.GetString(str);
}
syfsz 2007-01-23
  • 打赏
  • 举报
回复
using System;

/* The reason that i am using interface is that, in several
* weeks i will use a bitwise operator for have encryption and decryption
* */
public interface IBindesh
{
string encode(string str);
string decode(string str);
}

namespace EncryptionDecryption
{
/// <summary>
/// Summary description for EncryptionDecryption.
/// </summary>
public class EncryptionDecryption : IBindesh
{
public string encode(string str)
{
string htext = ""; // blank text

for ( int i = 0; i < str.Length; i++)
{
htext = htext + (char) (str[i] + 10 - 1 * 2);
}
return htext;
}

public string decode(string str)
{
string dtext = "";

for ( int i=0; i < str.Length; i++)
{
dtext = dtext + (char) (str[i] - 10 + 1*2);
}
return dtext;
}
}
}

----别人的
Ki1381 2007-01-23
  • 打赏
  • 举报
回复
using System;
using System.IO;
using System.Security.Cryptography;

namespace Ki1381Test
{
/// <summary>
/// DES加密/解密
/// </summary>
public class KiSecurity
{
const string KEY_64 = "xxxxxxxx";
const string IV_64 = "xxxxxxxx"; //注意了,是8个字符,64位

public KiSecurity()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public static string Encode(string data)
{
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);

DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
int i = cryptoProvider.KeySize;
MemoryStream ms = new MemoryStream();
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);

StreamWriter sw = new StreamWriter(cst);
sw.Write(data);
sw.Flush();
cst.FlushFinalBlock();
sw.Flush();

if (data == "")
{
return "";
}
else
{
return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
}

}

public static string Decode(string data)
{
byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);

byte[] byEnc;
try
{
byEnc = Convert.FromBase64String(data);
}
catch
{
return null;
}

DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream(byEnc);
CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cst);

if (data == "")
{
return "";
}
else
{
return sr.ReadToEnd();
}
}
}
}

hc8513589 2007-01-23
  • 打赏
  • 举报
回复
ding
孟子E章 2007-01-23
  • 打赏
  • 举报
回复
System.Security.Cryptography 命名空间

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧