java 加密方法,换成c#怎么写 5C

/**
* 定义 加密算法,可用DES,DESede,Blowfish
/
private static final String Algorithm = "DESede";
/
*
* 为加密密钥,长度为24字节
*/
final static byte[] keyBytes = "_ipudong_loginToken_plat".getBytes();

       public static String encryptMode(String src) {
    try {
        // 生成密钥
        SecretKey deskey = new SecretKeySpec(keyBytes, Algorithm);
        // 加密
        Cipher c1 = Cipher.getInstance(Algorithm);
        c1.init(Cipher.ENCRYPT_MODE, deskey);
        return byte2data(c1.doFinal(src.getBytes()));
    } catch (java.security.NoSuchAlgorithmException e1) {
        e1.printStackTrace();
    } catch (javax.crypto.NoSuchPaddingException e2) {
        e2.printStackTrace();
    } catch (java.lang.Exception e3) {
        e3.printStackTrace();
    }
    return null;
}

1个回答

你这是des加密算法,但是需要密钥,你的程序里没有看到

参考:https://blog.csdn.net/zhoufoxcn/article/details/1497095

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
getElementByTagName 换成 JQuery怎么写?
getElementByTagName 换成 JQuery怎么写?rn[code=JScript]var list = document.getElementsByTagName("label");rn if (v == 'one') rn for (var i = 0; i < list.length; i++) rn list[i].style.display = "none";rn rn $("#pnlOne").show();rn var rid = document.getElementById('datalistSize').firstChild.firstChild.firstChild.firstChild.attributes["id"].value;rn document.getElementById(rid).checked = "checked";rn setPanalVisible(rid);rn [/code]rnrn把这个改写一下~
下面这段加密方法的解密怎么写?
public static string Encrypt(string cleanString)rn rn Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);rn Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);rn rn return BitConverter.ToString(hashedBytes);rn
C#写的加密内容C#写的加密内容C#写的加密内容
C#写的加密内容C#写的加密内容C#写的加密内容C#写的加密内容C#写的加密内容C#写的加密内容C#写的加密内容C#写的加密内容
C#写的文件夹加密
C# 写的文件夹加密,工具简单,很适合初学者
java中转换成字符串的方法
①:toString()方法,在这种使用方法中,因为java.lang.Object类里已有public方法.toString(),所以对任何严格意义上的java对象都可以调用此方法。但在使用时要注意,必须保证object不是null值,否则将抛出NullPointerException异常。采用这种方法时,通常派生类会覆盖Object里的toString()方法。 ②:String.v
C# 加密方法 大全
包含多种C# 加密的经典方法(MD5 SHA1 DES 对称加密 非对称加密等等)
C#加密方法汇总
C#加密方法汇总,不同加密方法实例分析!
C#加密方法(两种)
C#加密方法................
c#加密方法
Md5加密 sha1加密
C#加密方法
C#常用的加密方法有那些?rn都分别是什么?rn包括字符串,文件,组件等rn谢谢
JAVA与C#一致的32位MD5加密方法
JAVA与C#一致的32位MD5加密方法
JAVA写的MD5加密
JAVA写的MD5加密,很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细
C#这段代码换成VB怎么写啊?
((Page)HttpContext.Current.Handler).ClientScript.RegisterStartupScript(typeof(string), "Error", sb.ToString());rnrn谢谢
C#与JAVA等价的3DES加密方法 CFB加密模式
C#版: public static string Encrypt3DES(string strString, string key, string iv) { TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider(); DES.Key = Encoding.UTF8.GetBytes(key); ...
JAVA MD5加密方法
一个JAVA开发的MD5加密方法。可以看看 :)
java的MD5加密方法。
系统自带有吗?还是得另写?
js写的md5加密方法!
js写的md5加密方法!js写的md5加密方法!js写的md5加密方法!
java 的RSA加密, 怎么在 .net(C#) 实现
java的代码,如下: rn[code=java]rnBigInteger Module = new BigInteger("module数据", 16);rn BigInteger publicExponent = new BigInteger("exponent", 16);rn RSAPublicKeySpec localRSAPublicKeySpec = new RSAPublicKeySpec(Module, publicExponent);rn KeyFactory fac = java.security.KeyFactory.getInstance("RSA");rn PublicKey pk = fac.generatePublic(localRSAPublicKeySpec);rnrn String text = "123"; //明文rn Cipher localCipher = Cipher.getInstance("RSA/ECB/NoPadding");rn localCipher.init(1, pk);rn byte[] arr = localCipher.doFinal(text.getBytes()); //生成的密文rn[/code]
ruby 写discuz加密方法
[code=PHP]rnfunction passport_encrypt($txt, $key) rn srand((double)microtime() * 1000000);rn $encrypt_key = md5(rand(0, 32000));rn $ctr = 0;rn $tmp = '';rn for($i = 0;$i < strlen($txt); $i++) rn $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;rn $tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);rn rn return base64_encode(passport_key($tmp, $key));rnrnrnrnfunction passport_key($txt, $encrypt_key) rn $encrypt_key = md5($encrypt_key);rn $ctr = 0;rn $tmp = '';rn for($i = 0; $i < strlen($txt); $i++) rn $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;rn $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];rn rn return $tmp;rnrnrn[/code]rn下边是用ruby写的,不过有点错误,麻烦大家帮忙找下,郁闷几天了!rn[code=Java] def encrypt(txt,key)rn encrypt_key=Digest::MD5.hexdigest(rand(32000).to_s)rn ctr=0rn tmp=''rn for i in (0..txt.length)rn ctr = (ctr == encrypt_key.length ? 0 : ctr) rn tmp += (encrypt_key[ctr].to_s+( txt[i] ^ encrypt_key[ctr]).to_s)rn ctr+=1rn endrnrn return Base64.encode64(passport_key(tmp,key))rn endrn rnrn def passport_key(txt,key)rn encrypt_key=Digest::MD5.hexdigest(key)rn ctr=0rn tmp=''rn for i in (0..txt.length)rn ctr= (ctr==encrypt_key.length ? 0 : ctr)rn tmp += (txt[i] ^ encrypt_key[ctr]).to_srn ctr+=1rn endrn rn return tmprn end[/code]
java简单加密方法
使用纯Java代码实现数据加密,DESede加密 及返回一个包含有 key(加密) fid(当前文件) name (文件/文件夹路径)的集合对象。可根据这个结果传到前台,通过jquery.ztree 或是dtree 直接生成文件夹结构的目录树
java 加密方法
java 加密方法<br>加密算法有:MD5 SHA-1 SHA-512
java密码加密方法
java密码加密,解密方法,一个好例子帮助大家学习!
Java Mac 加密方法
想要一个Java Mac加密和方法rnrn支持Ansi X9.9的Mac加密rnrn有方法提供或者有解决方案提供者重赏:)
Java MD5加密方法
package com.dataservice.utils;import java.security.MessageDigest;import org.springframework.util.Base64Utils;public class MD5Util { private static final String ALGORITHM = "MD5"; public static St
java键盘输入加密方法
package encipher; import java.util.Scanner; public class digitalEncryptor { public static void main(String[] args) { Scanner sc = new Scanner(System.in);// 键盘输入 System.out.println("请输入数字!"); dou
JAVA 常用加密方法
1.Base64  加密:org.apache.commons.codec.binary.Base64.encodeBase64(byte[] binaryData)  解密:org.apache.commons.codec.binary.Base64.decodeBase64(byte[] base64Data)2.Md5  加密:org.apache.commons.codec.digest...
C#写的EXE加密软件
我写的一个 C#写的EXE加密软件,基于 Kamal Patel 开发的代码转换类库制作请多支持我http://hanbing.xshwy.org
c#加密,java解密
如题,现在代码已经可以用了,就是有个问题,即用C#加密后,JAVA解密,部分解密过后的数据会显示为乱码,小弟以为是字符集转换的问题,找了半天毛病都没找到,请各位高手帮个忙rnrnc#代码rnrnusing System;rnusing System.Security;rnusing System.Security.Cryptography;rnusing System.IO;rnusing System.Text;rnusing System.Threading;rnnamespace WebApplication2rnrn /// rn /// DES3 的摘要说明。rn /// rn public class DES3rn rn public DES3()rn rn rn //密钥rn private const string sKey = "A3F2569DESJEIWBCJOTY45DYQWF68H1Y";rn //矢量,矢量可以为空rn private const string sIV = "qcDY6X+aPLw=";rn //构造一个对称算法rn private SymmetricAlgorithm mCSP = new TripleDESCryptoServiceProvider();rn #region public string EncryptString(string Value)rn /// 加密字符串rn /// 输入的字符串rn /// 加密后的字符串rn public string EncryptString(string Value)rn rn ICryptoTransform ct;rn MemoryStream ms;rn CryptoStream cs;rn byte[] byt;rn mCSP.Key = Convert.FromBase64String(sKey);rn mCSP.IV = Convert.FromBase64String(sIV);rn //指定加密的运算模式rn mCSP.Mode = System.Security.Cryptography.CipherMode.ECB;rn //获取或设置加密算法的填充模式rn mCSP.Padding = System.Security.Cryptography.PaddingMode.PKCS7;rn ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV);rn byt = Encoding.UTF8.GetBytes(Value);rn ms = new MemoryStream();rn cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);rn cs.Write(byt, 0, byt.Length);rn cs.FlushFinalBlock();rn cs.Close();rn return Convert.ToBase64String(ms.ToArray());rn rn #endregionrn rn rn rn rnjava代码rn rnpackage des;rnimport javax.crypto.Cipher;rnimport javax.crypto.NoSuchPaddingException;rnimport javax.crypto.SecretKey;rnimport java.security.NoSuchAlgorithmException;rnimport sun.misc.*;rnimport java.io.IOException;rnimport java.io.UnsupportedEncodingException;rnimport javax.crypto.BadPaddingException;rnimport javax.crypto.IllegalBlockSizeException;rnimport javax.crypto.spec.SecretKeySpec;rnimport java.security.*;rnimport javax.crypto.SecretKeyFactory;rnimport java.security.spec.*;rnimport javax.crypto.spec.DESedeKeySpec;rn/**rn解密rn */rnpublic class DES rn private static String Algorithm = "DESede";//加密算法的名称rn private static Cipher c;//密码器rn private static byte[] cipherByte;rn private static SecretKey deskey;//密钥rn private static String keyString = "A3F2569DESJEIWBCJOTY45DYQWF68H1Y";//获得密钥的参数rn //对base64编码的string解码成byte数组rn public byte[] deBase64(String parm) throws IOException rn BASE64Decoder dec=new BASE64Decoder();rn byte[] dnParm = dec.decodeBuffer(parm);rn System.out.println(dnParm.length);rn System.out.println(dnParm);rn return dnParm;rn rn //把密钥参数转为byte数组rn public byte[] dBase64(String parm) throws IOException rn BASE64Decoder dec=new BASE64Decoder();rn byte[] dnParm = dec.decodeBuffer(parm);rn return dnParm;rn rn /**rn * 对 Byte 数组进行解密rn * @param buff 要解密的数据rn * @return 返回加密后的 Stringrn */rn public static String createDecryptor(byte[] buff) throwsrn NoSuchPaddingException, NoSuchAlgorithmException,rn UnsupportedEncodingException rn try rn c.init(Cipher.DECRYPT_MODE, deskey);//初始化密码器,用密钥deskey,进入解密模式rn cipherByte = c.doFinal(buff);rn rn catch(java.security.InvalidKeyException ex)rn ex.printStackTrace();rn rn catch(javax.crypto.BadPaddingException ex)rn ex.printStackTrace();rn rn catch(javax.crypto.IllegalBlockSizeException ex)rn ex.printStackTrace();rn rn return (new String(cipherByte,"UTF-8"));rn rn public void getKey(String key) throws IOException, InvalidKeyException,rn InvalidKeySpecException rn byte[] dKey = dBase64(key);rn try rn deskey=new javax.crypto.spec.SecretKeySpec(dKey,Algorithm);rn c = Cipher.getInstance(Algorithm);rn rn catch (NoSuchPaddingException ex) rn rn catch (NoSuchAlgorithmException ex) rn rn rn public static void main(String args[]) throws IOException,rn NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException,rn InvalidKeyException, IOException rn DES des = new DES();rn des.getKey(keyString);rn byte[] dBy = des.deBase64("1ZVasdJJco1qccDnnfQfb8QeaARxhkR6");rn String dStr = des.createDecryptor(dBy);rn System.out.println("解:"+dStr);rn rn
C# MD加密 求32位加密方法
16位方法如下:rn[code=C#]rn/// rn /// 获得MD5的16进制结果rn /// rn public static string GetMD5(string encryptStr)rn rn System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider();rn byte[] bytResult = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(encryptStr));rn string strResult = BitConverter.ToString(bytResult);rn strResult = strResult.Replace("-", "");rn return strResult;rnrn rn[/code]rn网上查了下,乱糟糟的一堆,不要复制过来了。 rn有没有整合好的方法,直接调用就可以?通过40分送上,秒结贴。
下句jquery 换成js 得怎么写啊
下句jquery 换成js 得怎么写啊 rnrn$(function () rn $("li:has(ul)").hover(rnfunction () rn $(this).children("ul").show();rn,rnfunction () rn $(this).children("ul").hide();rn)rn )
C#加密JAVA解密
C# 加密 JAVA 解密源码 using System; using System.IO; using System.Security.Cryptography; namespace WindowsApplication1 { /// <summary> /// Security 的摘要说明。 /// </summary> public class Security { const string KEY_64 = "flxmtdes"; const string IV_64 = "flxmtIvS"; public Security() { // // 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(); 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); return sr.ReadToEnd(); } } }
java与C#的PBE加密
java的PBEWithMD5AndDES加密 C#的PBEWithMD5AndDES加密
这个SQL换成linq怎么写啊
string sql = "";rn sql = "select * from Tasks where 1=1";rn if (!string.IsNullOrEmpty(ddlpriority.SelectedValue))rn rn sql += sql +"and id="+ Convert.ToInt32(ddlpriority.SelectedValue);rn rn-------------------------------------------------------------------------------rn NPMSLinqDataContext ctxt = new NPMSLinqDataContext();rn string linqstring=string.Empty;rn linqstring="";rn int _priority = 0;rn int _status = 0;rn DateTime _objtime;rn if (!string.IsNullOrEmpty(ddlpriority.SelectedValue))rn rn _priority = Convert.ToInt32(ddlpriority.SelectedValue);rn rn var q = from c in ctxt.Tasksrn where 1=1 rn && c.priority == (_priority == 0 ? : _priority) 这个地方怎么写啊 rn ......... rn select c;rn rn repeaterReportInfo.DataSource = q;rn repeaterReportInfo.DataBind();rn rn 第一次用LINQ 做项目 不要见笑
AxWebBrowser代码换成WebBrowser的应该怎么写?
private void button2_Click(object sender, System.EventArgs e)rn rn mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;rn mshtml.IHTMLFormElement f1 =(mshtml.IHTMLFormElement)doc.all.item ("form1",0);rn ((mshtml.IHTMLFormElement)(f1)).submit();rn mshtml.IHTMLElement Element = (mshtml.IHTMLElement)doc.all.item("button1", 0);rn Element.click();rn
access换成SQL 查询怎么写
把一个程序转成了用SQL2000数据库的rnrn没用过 查询不会写啊 rnrn首先是窗体 用SQL是不是不用ADODC 而是改用DATA啊 rnrn然后查询rnSet db = New Connectionrndb.CursorLocation = adUseClientrndb.Open "Provider=SQLOLEDB.1;User ID=sa;password=sa;Initial Catalog=abc;Data Source=(local)" '建立连接rnSet rs = New Recordsetrnrs.Open "select * from chanpin", db, adOpenStatic, adLockOptimistic '打开记录集rn SQL = "select * from chanpin where val(kuchun) <=" & Val(Text1.Text) & " and mingcheng like '%" & Text2.Text & "%'"rnrn'Adodc1.ConnectionString = "Provider=SQLOLEDB.1;User ID=sa;password=sa;Initial Catalog=abc;Data Source=(local)"rnrnData1.RecordSource = SQLrn Data1.Refreshrn DataGrid1.Refreshrn ‘Set DataGrid1.DataSource = rsrn DataGrid1.Columns(0).Width = 4000rnDataGrid1.Columns(0).Caption = "产品名称"rnDataGrid1.Columns(1).Width = 1200rnDataGrid1.Columns(1).Caption = "单价"rnDataGrid1.Columns(2).Width = 1200rnDataGrid1.Columns(2).Caption = "库存"rnDataGrid1.Columns(3).Width = 1200rnDataGrid1.Columns(3).Caption = "类别"rnrn报错的 很无奈 没用过DATA呢 rnrn应该怎么写啊 请教
求助mssql的查询语句换成access怎么写???
select F.ForumId,F.IsSelected,F.ForumName,F.ForumUrl,F.ForumPr,F.ForumBr,F.ForumNote,(select count(1) from Board where ForumId=F.ForumId) as BrardNumber ,(select count(1) from User where ForumId=F.ForumId) as UserNumber from Forum F order by ForumIdrnrn原本是mssql的数据库,现在我要用access数据库,但是同样的语句报错:语法错误,我对access的查询语句不熟,求正确的写法。
求助:mssql的查询语句换成access怎么写?
select F.ForumId,F.IsSelected,F.ForumName,F.ForumUrl,F.ForumPr,F.ForumBr,F.ForumNote,(select count(1) from Board where ForumId=F.ForumId) as BrardNumber ,(select count(1) from User where ForumId=F.ForumId) as UserNumber from Forum F order by ForumIdrnrn原本是mssql的数据库,现在我要用access数据库,但是同样的语句报错:语法错误,我对access的查询语句不熟,求正确的写法。
这段代码换成vb.net 怎么写
[img=https://img-bbs.csdn.net/upload/201310/31/1383191792_943104.jpg][/img]rnrn关键是rnbyte* p=(byte*) data.scan()rn和之后的rnb=p[0];rng=p[1]rnr=p[2]rnrn注意在vc下p是个地址,所以p[0]什么等于的是地址里面的值rn而rnvb.net下data.scan返回的是intptr,相当于一个整形rn如何使用获得p[0]的效果?
Reset把按钮换成图片,怎么写?
rn用图片按钮,怎么写?rnrn小弟现在就10分了!rn
把? 换成泛型T,应该怎么写?
n这句话要是把? 换成泛型T,应该怎么写?nn```n List result = new ArrayList<>();n```nnn```n public interface ComExcel nnn```nnnn
相关热词 c#检测非法字符 c#双屏截图 c#中怎么关闭线程 c# 显示服务器上的图片 api嵌入窗口 c# c# 控制网页 c# encrypt c#微信网页版登录 c# login 居中 c# 考试软件