要求:
用加密KEY: SpanDivAHFont0531
加密算法:DES
加密编码:Base64
将 371325751788249 加密后能得到 sWql7JYSxGRhqgjOfx+9gQ==
该加密结果已通过下面的.Net代码验证
有能解的朋友请加QQ:279443771 ,注明:des加密
也可点击网站上的QQ号直接发消息:
http://wannianchuan.net/加密结果通过验证后立即付款。
参考:
.Net代码
public static class DES
{
//默认密钥向量
private static byte[] Keys = { 1, 2, 3, 4, 5, 6, 7, 8 };
public static string Encode(string encryptString, string encryptKey)
{
encryptKey = encryptKey.Substring(0, 8);
byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey);
byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
dCSP.Key = rgbKey;
dCSP.IV = Keys;
dCSP.Padding = PaddingMode.PKCS7;
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
return Convert.ToBase64String(mStream.ToArray());
}
public static string Decode(string decryptString, string decryptKey)
{
try
{
decryptKey = decryptKey.Substring(0, 8);
byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);
byte[] inputByteArray = Convert.FromBase64String(decryptString);
DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
DCSP.Key = rgbKey;
DCSP.IV = Keys;
DCSP.Padding = PaddingMode.PKCS7;
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
return Encoding.UTF8.GetString(mStream.ToArray());
}
catch(Exception ex)
{
return ex.Message;
}
}
string a = DES.Encode("371325751788249", "SpanDivAHFont0531");
Response.Write(a + "<br>" + DES.Decode(a,"SpanDivAHFont0531"));
//// sWql7JYSxGRhqgjOfx+9gQ==
//// 371325751788249
另外附上Java代码:
private static byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };
IvParameterSpec zeroIv = new IvParameterSpec(iv);
SecretKeySpec key = new SecretKeySpec(getKey(encryptKey.getBytes()), "DES");
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv);
byte[] encryptedData = cipher.doFinal(encryptString.getBytes());
return Base64.encode(encryptedData);
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.