Java加密代码 转换成Net版
java版本自己封装base64
- package com.qhong;
- import java.io.UnsupportedEncodingException;
- import org.apache.commons.lang.StringUtils;
- public class Base64Utils {
- /**
- * Base64方法重写
- */
- public static void main(String[] args) {
- String aa = "商户私有域";
- String aaa = byteArrayToBase64(aa.getBytes());
- System.out.println(aaa);
- try {
- String bb = new String(base64ToByteArray(aaa));
- System.out.println(bb);
- String tests = encodeBuffer("【厚本金融】", "GBK");
- System.out.println(tests);
- System.out.println(decodeBuffer(tests, "GBK"));
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * 将字符数组base64字符串
- * @param a 要转化的字符数组
- * @return base64字符串
- */
- public static String byteArrayToBase64(byte[] a) {
- int aLen = a.length; //总长度
- int numFullGroups = aLen / 3; //以3个byte组成以4个字符为一组的组数
- int numBytesInPartialGroup = aLen - 3 * numFullGroups; //余数
- int resultLen = 4 * ((aLen + 2) / 3); //输出长度总是4倍数,如果有余数,(aLen+2)/3保证将余数包含,并有空间放置填充符=
- StringBuffer result = new StringBuffer(resultLen);
- int inCursor = 0;
- for (int i = 0; i < numFullGroups; i++) {
- int byte0 = a[inCursor++] & 0xff;
- int byte1 = a[inCursor++] & 0xff;
- int byte2 = a[inCursor++] & 0xff;
- result.append(intToBase64[byte0 >> 2]);
- result.append(intToBase64[(byte0 << 4) & 0x3f | (byte1 >> 4)]);
- result.append(intToBase64[(byte1 << 2) & 0x3f | (byte2 >> 6)]);
- result.append(intToBase64[byte2 & 0x3f]);
- }
- //处理余数
- if (numBytesInPartialGroup != 0) {
- int byte0 = a[inCursor++] & 0xff;
- result.append(intToBase64[byte0 >> 2]);
- //余数为1
- if (numBytesInPartialGroup == 1) {
- result.append(intToBase64[(byte0 << 4) & 0x3f]);
- result.append("==");
- } else {
- // 余数为2
- int byte1 = a[inCursor++] & 0xff;
- result.append(intToBase64[(byte0 << 4) & 0x3f | (byte1 >> 4)]);
- result.append(intToBase64[(byte1 << 2) & 0x3f]);
- result.append('=');
- }
- }
- return result.toString();
- }
- static final char intToBase64[] = { 'A', 'B', 'C', 'D', 'E', 'F', /* 索引 0 ~ 5*/
- 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', /* 索引6 ~ 18*/
- 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', /* 索引 19 ~ 31*/
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', /* 索引 32 ~ 44*/
- 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', /* 索引 45 ~ 57*/
- '6', '7', '8', '9', '.'/*原先是字符+*/, '_'/*原先是字符/ */ }; /* 索引58 ~ 63*/
- /**
- * base64字符串还原为字符数组
- * @param s base64字符串
- * @return 还原后的字符串数组
- * @throws Exception
- */
- public static byte[] base64ToByteArray(String s) throws Exception {
- //字符总长必须是4的倍数
- int sLen = s.length();
- int numGroups = sLen / 4;
- if (4 * numGroups != sLen)
- throw new IllegalArgumentException(
- "字串长度必须是4的倍数");
- //余1个byte则算漏了两个byte,余2个byte则算漏掉了1个byte
- int missingBytesInLastGroup = 0;
- int numFullGroups = numGroups;
- if (sLen != 0) {
- //余2个byte的情况
- if (s.charAt(sLen - 1) == '=') {
- missingBytesInLastGroup++;
- //如果有余数发生,则完整3个byte组数少一个。
- numFullGroups--;
- }
- //余1个byte的情况
- if (s.charAt(sLen - 2) == '=')
- missingBytesInLastGroup++;
- }
- //总字节长度
- byte[] result = new byte[3 * numGroups - missingBytesInLastGroup];
- try {
- int inCursor = 0, outCursor = 0;
- for (int i = 0; i < numFullGroups; i++) {
- int ch0 = base64toInt(s.charAt(inCursor++), base64ToInt);
- int ch1 = base64toInt(s.charAt(inCursor++), base64ToInt);
- int ch2 = base64toInt(s.charAt(inCursor++), base64ToInt);
- int ch3 = base64toInt(s.charAt(inCursor++), base64ToInt);
- result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4));
- result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2));
- result[outCursor++] = (byte) ((ch2 << 6) | ch3);
- }
- if (missingBytesInLastGroup != 0) {
- int ch0 = base64toInt(s.charAt(inCursor++), base64ToInt);
- int ch1 = base64toInt(s.charAt(inCursor++), base64ToInt);
- //不管余1还是余2个byte,肯定要解码一个byte。
- result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4));
- //如果余2个,即差一个才构成3byte,那么还要解码第二个byte。
- if (missingBytesInLastGroup == 1) {
- int ch2 = base64toInt(s.charAt(inCursor++), base64ToInt);
- result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2));
- }
- }
- } catch (Exception e) {
- throw e;
- }
- return result;
- }
- private static int base64toInt(char c, byte[] alphaToInt) throws Exception {
- int result = alphaToInt[c];
- if (result < 0)
- throw new Exception("illegal index!");//非法索引值
- return result;
- }
- static final byte base64ToInt[] = { -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1/*原先是62*/, -1, -1, 62/*原先是-1*/, -1/*原先是63*/, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1,
- -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
- 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1,
- 63/*原先是-1*/, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
- /**
- * @param str原始中文字符串
- * @param charset进行二进制字符串转化的字符编码
- * @return 二进制字符串
- */
- public static String encodeBuffer(String str ,String charset){
- if (str == null) {
- str = StringUtils.EMPTY;
- }
- try {
- return Base64Utils.byteArrayToBase64(str.getBytes(charset));
- } catch (UnsupportedEncodingException e) {
- return new String();
- }
- }
- /**
- * 此方法为还原中文字符串转化后的二进制字符串
- * @param str 二进制字符串
- * @param charset 字符编码
- * @return 正常中文字符串
- */
- public static String decodeBuffer(String str ,String charset){
- if (str == null) {
- return str = StringUtils.EMPTY;
- }
- try {
- byte[] byteStr;
- try {
- byteStr = Base64Utils.base64ToByteArray(str.trim());
- } catch (Exception e) {
- return new String();
- }
- return new String(byteStr,charset);
- } catch (UnsupportedEncodingException e) {
- return new String();
- }
- }
- }
与上面对应的net版本:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace ConsoleApplication2
- {
- public class Base64Utils
- {
- ///**
- // * Base64方法重写
- // */
- //public static void main(String[] args)
- //{
- // String aa = "商户私有域";
- // String aaa = byteArrayToBase64(aa.getBytes());
- // System.out.println(aaa);
- // try
- // {
- // String bb = new String(base64ToByteArray(aaa));
- // System.out.println(bb);
- // String tests = encodeBuffer("【厚本金融】", "GBK");
- // System.out.println(tests);
- // System.out.println(decodeBuffer(tests, "GBK"));
- // }
- // catch (Exception e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- //}
- /**
- * 将字符数组base64字符串
- * @param a 要转化的字符数组
- * @return base64字符串
- */
- public static String byteArrayToBase64(byte[] a)
- {
- int aLen = a.Length; //总长度
- int numFullGroups = aLen / 3; //以3个byte组成以4个字符为一组的组数
- int numBytesInPartialGroup = aLen - 3 * numFullGroups; //余数
- int resultLen = 4 * ((aLen + 2) / 3); //输出长度总是4倍数,如果有余数,(aLen+2)/3保证将余数包含,并有空间放置填充符=
- //StringBuffer result = new StringBuffer(resultLen);
- StringBuilder result = new StringBuilder(resultLen);
- int inCursor = 0;
- for (int i = 0; i < numFullGroups; i++)
- {
- int byte0 = a[inCursor++] & 0xff;
- int byte1 = a[inCursor++] & 0xff;
- int byte2 = a[inCursor++] & 0xff;
- result.Append(intToBase64[byte0 >> 2]);
- result.Append(intToBase64[(byte0 << 4) & 0x3f | (byte1 >> 4)]);
- result.Append(intToBase64[(byte1 << 2) & 0x3f | (byte2 >> 6)]);
- result.Append(intToBase64[byte2 & 0x3f]);
- }
- //处理余数
- if (numBytesInPartialGroup != 0)
- {
- int byte0 = a[inCursor++] & 0xff;
- result.Append(intToBase64[byte0 >> 2]);
- //余数为1
- if (numBytesInPartialGroup == 1)
- {
- result.Append(intToBase64[(byte0 << 4) & 0x3f]);
- result.Append("==");
- }
- else
- {
- // 余数为2
- int byte1 = a[inCursor++] & 0xff;
- result.Append(intToBase64[(byte0 << 4) & 0x3f | (byte1 >> 4)]);
- result.Append(intToBase64[(byte1 << 2) & 0x3f]);
- result.Append('=');
- }
- }
- return result.ToString();
- }
- static readonly char[] intToBase64 = { 'A', 'B', 'C', 'D', 'E', 'F', /* 索引 0 ~ 5*/
- 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', /* 索引6 ~ 18*/
- 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', /* 索引 19 ~ 31*/
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', /* 索引 32 ~ 44*/
- 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', /* 索引 45 ~ 57*/
- '6', '7', '8', '9', '.'/*原先是字符+*/, '_'/*原先是字符/ */ }; /* 索引58 ~ 63*/
- /**
- * base64字符串还原为字符数组
- * @param s base64字符串
- * @return 还原后的字符串数组
- * @throws Exception
- */
- public static byte[] base64ToByteArray(String s)
- {
- //字符总长必须是4的倍数
- int sLen = s.Length;
- int numGroups = sLen / 4;
- if (4 * numGroups != sLen)
- throw new ArgumentException(
- "字串长度必须是4的倍数");
- //余1个byte则算漏了两个byte,余2个byte则算漏掉了1个byte
- int missingBytesInLastGroup = 0;
- int numFullGroups = numGroups;
- if (sLen != 0)
- {
- //余2个byte的情况
- if (s.charAt(sLen - 1) == '=')
- {
- missingBytesInLastGroup++;
- //如果有余数发生,则完整3个byte组数少一个。
- numFullGroups--;
- }
- //余1个byte的情况
- if (s.charAt(sLen - 2) == '=')
- missingBytesInLastGroup++;
- }
- //总字节长度
- byte[] result = new byte[3 * numGroups - missingBytesInLastGroup];
- try
- {
- int inCursor = 0, outCursor = 0;
- for (int i = 0; i < numFullGroups; i++)
- {
- int ch0 = base64toInt(s.charAt(inCursor++), base64ToInt);
- int ch1 = base64toInt(s.charAt(inCursor++), base64ToInt);
- int ch2 = base64toInt(s.charAt(inCursor++), base64ToInt);
- int ch3 = base64toInt(s.charAt(inCursor++), base64ToInt);
- result[outCursor++] = (byte)((ch0 << 2) | (ch1 >> 4));
- result[outCursor++] = (byte)((ch1 << 4) | (ch2 >> 2));
- result[outCursor++] = (byte)((ch2 << 6) | ch3);
- }
- if (missingBytesInLastGroup != 0)
- {
- int ch0 = base64toInt(s.charAt(inCursor++), base64ToInt);
- int ch1 = base64toInt(s.charAt(inCursor++), base64ToInt);
- //不管余1还是余2个byte,肯定要解码一个byte。
- result[outCursor++] = (byte)((ch0 << 2) | (ch1 >> 4));
- //如果余2个,即差一个才构成3byte,那么还要解码第二个byte。
- if (missingBytesInLastGroup == 1)
- {
- int ch2 = base64toInt(s.charAt(inCursor++), base64ToInt);
- result[outCursor++] = (byte)((ch1 << 4) | (ch2 >> 2));
- }
- }
- }
- catch (Exception e)
- {
- throw e;
- }
- return result;
- }
- private static int base64toInt(char c, int[] alphaToInt)
- {
- int result = alphaToInt[c];
- if (result < 0)
- throw new Exception("illegal index!");//非法索引值
- return result;
- }
- static readonly int[] base64ToInt = { 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1/*原先是62*/, 1, 1, 62/*原先是1*/, 1/*原先是63*/, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 1,
- 1, 1, 1, 1, 1, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
- 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 1, 1, 1, 1,
- 63/*原先是1*/, 1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
- //static readonly byte[] base64ToInt = { -1, -1, -1, -1, -1, -1, -1, -1,
- // -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- // -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- // -1, -1/*原先是62*/, -1, -1, 62/*原先是-1*/, -1/*原先是63*/, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1,
- // -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
- // 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1,
- // 63/*原先是-1*/, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- // 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
- /**
- * @param str原始中文字符串
- * @param charset进行二进制字符串转化的字符编码
- * @return 二进制字符串
- */
- public static String encodeBuffer(String str)
- {
- if (str == null)
- {
- str = String.Empty;
- }
- try
- {
- return Base64Utils.byteArrayToBase64(Encoding.UTF8.GetBytes(str));
- }
- catch (Exception e)
- {
- return String.Empty;
- }
- }
- /**
- * 此方法为还原中文字符串转化后的二进制字符串
- * @param str 二进制字符串
- * @param charset 字符编码
- * @return 正常中文字符串
- */
- public static String decodeBuffer(String str)
- {
- if (str == null)
- {
- return str = String.Empty;
- }
- try
- {
- byte[] byteStr;
- try
- {
- byteStr = Base64Utils.base64ToByteArray(str.Trim());
- }
- catch (Exception e)
- {
- return String.Empty;
- }
- return Encoding.UTF8.GetString(byteStr);
- }
- catch (Exception e)
- {
- return String.Empty;
- }
- }
- }
- }
3des加密,解密:
java版本:
- package com.qhong;
- import java.security.Key;
- import javax.crypto.Cipher;
- import javax.crypto.SecretKeyFactory;
- import javax.crypto.spec.DESedeKeySpec;
- import javax.crypto.spec.IvParameterSpec;
- /*import javax.crypto.Cipher;
- import javax.crypto.SecretKeyFactory;
- import javax.crypto.spec.DESedeKeySpec;
- import javax.crypto.spec.IvParameterSpec;*/
- import sun.misc.BASE64Decoder;
- import sun.misc.BASE64Encoder;
- public class EncodeUtil {
- public static void main(String[] args) throws Exception {
- /* byte[] key=new BASE64Decoder().decodeBuffer("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4"); */
- byte[] key=new BASE64Decoder().decodeBuffer("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4");
- byte[] keyiv = { 1, 2, 3, 4, 5, 6, 7, 8 };
- byte[] data="中国ABCabc123".getBytes("UTF-8");
- System.out.println("ECB加密解密");
- byte[] str3 = des3EncodeECB(key,data );
- byte[] str4 = ees3DecodeECB(key, str3);
- System.out.println(new BASE64Encoder().encode(str3));
- System.out.println(new String(str4, "UTF-8"));
- System.out.println();
- System.out.println("CBC加密解密");
- byte[] str5 = des3EncodeCBC(key, keyiv, data);
- byte[] str6 = des3DecodeCBC(key, keyiv, str5);
- System.out.println(new BASE64Encoder().encode(str5));
- System.out.println(new String(str6, "UTF-8"));
- }
- /**
- * ECB加密,不要IV
- * @param key 密钥
- * @param data 明文
- * @return Base64编码的密文
- * @throws Exception
- */
- public static byte[] des3EncodeECB(byte[] key, byte[] data)
- throws Exception {
- Key deskey = null;
- DESedeKeySpec spec = new DESedeKeySpec(key);
- SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
- deskey = keyfactory.generateSecret(spec);
- Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding");
- cipher.init(Cipher.ENCRYPT_MODE, deskey);
- byte[] bOut = cipher.doFinal(data);
- return bOut;
- }
- /**
- * ECB解密,不要IV
- * @param key 密钥
- * @param data Base64编码的密文
- * @return 明文
- * @throws Exception
- */
- public static byte[] ees3DecodeECB(byte[] key, byte[] data)
- throws Exception {
- Key deskey = null;
- DESedeKeySpec spec = new DESedeKeySpec(key);
- SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
- deskey = keyfactory.generateSecret(spec);
- Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding");
- cipher.init(Cipher.DECRYPT_MODE, deskey);
- byte[] bOut = cipher.doFinal(data);
- return bOut;
- }
- /**
- * CBC加密
- * @param key 密钥
- * @param keyiv IV
- * @param data 明文
- * @return Base64编码的密文
- * @throws Exception
- */
- public static byte[] des3EncodeCBC(byte[] key, byte[] keyiv, byte[] data)
- throws Exception {
- Key deskey = null;
- DESedeKeySpec spec = new DESedeKeySpec(key);
- SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
- deskey = keyfactory.generateSecret(spec);
- Cipher cipher = Cipher.getInstance("desede" + "/CBC/PKCS5Padding");
- IvParameterSpec ips = new IvParameterSpec(keyiv);
- cipher.init(Cipher.ENCRYPT_MODE, deskey, ips);
- byte[] bOut = cipher.doFinal(data);
- return bOut;
- }
- /**
- * CBC解密
- * @param key 密钥
- * @param keyiv IV
- * @param data Base64编码的密文
- * @return 明文
- * @throws Exception
- */
- public static byte[] des3DecodeCBC(byte[] key, byte[] keyiv, byte[] data)
- throws Exception {
- Key deskey = null;
- DESedeKeySpec spec = new DESedeKeySpec(key);
- SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
- deskey = keyfactory.generateSecret(spec);
- Cipher cipher = Cipher.getInstance("desede" + "/CBC/PKCS5Padding");
- IvParameterSpec ips = new IvParameterSpec(keyiv);
- cipher.init(Cipher.DECRYPT_MODE, deskey, ips);
- byte[] bOut = cipher.doFinal(data);
- return bOut;
- }
- }
NET版本:(只有ECS)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Threading.Tasks;
- using System.Security.Cryptography;
- namespace Rongzi.ToolKits.Core.HBJR
- {
- public class EncodeUtil
- {
- /**
- * ECB加密,不要IV
- * @param key 密钥
- * @param data 明文
- * @return Base64编码的密文
- * @throws Exception
- */
- public static byte[] des3EncodeECB(byte[] key, byte[] data)
- {
- // Create a MemoryStream.
- MemoryStream mStream = new MemoryStream();
- TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();
- tdsp.Mode = CipherMode.ECB;
- tdsp.Padding = PaddingMode.PKCS7;
- // Create a CryptoStream using the MemoryStream
- // and the passed key and initialization vector (IV).
- CryptoStream cStream = new CryptoStream(mStream,
- tdsp.CreateEncryptor(key, null),
- CryptoStreamMode.Write);
- // Write the byte array to the crypto stream and flush it.
- cStream.Write(data, 0, data.Length);
- cStream.FlushFinalBlock();
- // Get an array of bytes from the
- // MemoryStream that holds the
- // encrypted data.
- byte[] ret = mStream.ToArray();
- // Close the streams.
- cStream.Close();
- mStream.Close();
- // Return the encrypted buffer.
- return ret;
- }
- /**
- * ECB解密,不要IV
- * @param key 密钥
- * @param data Base64编码的密文
- * @return 明文
- * @throws Exception
- */
- public static byte[] ees3DecodeECB(byte[] key, byte[] data)
- {
- try
- {
- // Create a new MemoryStream using the passed
- // array of encrypted data.
- MemoryStream msDecrypt = new MemoryStream(data);
- TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();
- tdsp.Mode = CipherMode.ECB;
- tdsp.Padding = PaddingMode.PKCS7;
- // Create a CryptoStream using the MemoryStream
- // and the passed key and initialization vector (IV).
- CryptoStream csDecrypt = new CryptoStream(msDecrypt,
- tdsp.CreateDecryptor(key, null),
- CryptoStreamMode.Read);
- // Create buffer to hold the decrypted data.
- byte[] fromEncrypt = new byte[data.Length];
- // Read the decrypted data out of the crypto stream
- // and place it into the temporary buffer.
- csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
- //Convert the buffer into a string and return it.
- return fromEncrypt;
- }
- catch (CryptographicException e)
- {
- Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
- return null;
- }
- }
- }
- }
http://yilinliu.blogspot.hk/2010/07/c-java-net-descryptoserviceprovider-vs.html
http://www.cnblogs.com/liluping860122/p/4026015.html
http://www.cnblogs.com/AloneSword/archive/2013/12/11/3469219.html
Java加密代码 转换成Net版的更多相关文章
- PC网站转换成手机版
博客地址:https://www.cnblogs.com/zxtceq/p/5714606.html 一天完成把PC网站改为自适应!原来这么简单! http://www.webkaka.com/blo ...
- Java-Runoob-高级教程-实例-时间处理:04. Java 实例 - 时间戳转换成时间
ylbtech-Java-Runoob-高级教程-实例-时间处理:04. Java 实例 - 时间戳转换成时间 1.返回顶部 1. Java 实例 - 时间戳转换成时间 Java 实例 以下实例演示 ...
- android112 jni 把java的字符串转换成c的字符串,数组处理
package com.itheima.charencode; import android.os.Bundle; import android.app.Activity; import androi ...
- Java 把 InputStream 转换成 String 的几种方法
我们在 Java 中经常会碰到如何把 InputStream 转换成 String 的情形,比如从文件或网络得到一个 InputStream,需要转换成字符串输出或赋给别的变量. 未真正关注这个问题之 ...
- java将图片转换成二进制
package com.oumyye.图片; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; imp ...
- JAVA CST时间 转换成Date
Mybatis中处理Oracle时间类型是个比较麻烦的问题,特别是需要用到时间做比较的,可参考以下代码与思路: 格式化CST时间 SimpleDateFormat sdf = new SimpleDa ...
- [JavaWeb基础] 025.JAVA把word转换成html
用第三方插件POI把word文档转换成HTML,下面直接上代码 package com.babybus.sdteam.wordtopdf; import java.io.BufferedWriter; ...
- Java Keytools 证书转换成Openssl 的PEM 文件或keytools 导出私钥文件
上一遍又说到Godaddy 生请证书流程与操作: 现因使用Incapsula 防护使用到https,在添加网站时需要自定义证书,其中需要上传私钥信息,因公钥是能过keytool 生成所以需要导出私钥信 ...
- Java实现字符串转换成整数
1 问题描述 输入一个由数字组成的字符串,请把它转换成整数并输出.例如,输入字符串"123",输出整数123. 请写出一个函数实现该功能,不能使用库函数. 2 解决方案 解答本问题 ...
随机推荐
- 【CSS系列】块级元素和行内元素
块级元素: 块级元素生成一个元素框,默认会填充其父元素的内容区,旁边不能有其他元素,换句话说,它在元素框之前和之后生成了“分隔符”. 列表项是块级额元素的一个特例,除了表现方式与其他块元素一致,列表项 ...
- 【jQuery系列之插件】jquery插件之jquery-validation
equalTo方法: equalTo: function( value, element, param ) { // Bind to the blur event of the target in o ...
- 旅游吧!我在这里 ——旅游相册POI搜索:找回你的足迹
版权声明:本文由林少彬原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/89 来源:腾云阁 https://www.qclou ...
- JQuery中$.ajax()方法参数详解 转载
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- struts2漏洞原理
一.struts2简介: 目前web框架中非常流行的都是mvc设计模式.经典例子例如:python的Django.Flask:java的ssm等.因为使用MVC设计模式,所以在框架内部处理用户数据流参 ...
- Windows Phone 几种弹出框提示方式
首先,我们需要在网络上下载一个Coding4Fun 然后,引用 using Coding4Fun.Phone.Controls.Toolkit; using Codin ...
- android麦克风自录自放demo
extends:http://blog.csdn.net/trbbadboy/article/details/7865530 是一个直接播放麦克风采集到的声音线程类: class RecordThre ...
- tpcc-mysql安装、使用、结果解读
请点击:http://www.aikaiyuan.com/8687.html 错误处理: ln -s /usr/local/mysql/lib/libmysqlclient.so. /usr/lib6 ...
- fiddler 面板内显示IP地址
1.打开fiddler, 快捷键Ctrl+R (菜单->Rules->Customize Rules…) 然后在CustomRules.js文件里Ctrl+F查找字符串:static f ...
- PHP 的“魔术常量”
名称 说明 __LINE__ 文件中的当前行号. __FILE__ 文件的完整路径和文件名.如果用在被包含文件中,则返回被包含的文件名.自 PHP 4.0.2 起,__FILE__ 总是包含一个绝对路 ...