///<summary> /// 加密 /// </summary> /// <returns></returns> public static byte[] encryptedData(byte[] encData, SDKConfig con) { try { byte[] enBytes = CertUtil.GetEncryptKey(con).Encrypt(encData, false); return(enBytes); } catch (Exception e) { log.Error("encryptedData error: " + e.Message); return(new byte[0]); } }
///// <summary> ///// 密码计算 ///// </summary> ///// <param name="aPin"></param> ///// <returns></returns> //private static byte[] pin2PinBlock(string aPin) //{ // int tTemp = 1; // int tPinLen = aPin.Length; // byte[] tByte = new byte[8]; // try // { // tByte[0] = (byte)Convert.ToInt32(tPinLen.ToString(), 10); // if (tPinLen % 2 == 0) // { // for (int i = 0; i < tPinLen; ) // { // string a = aPin.Substring(i, 2).Trim(); // tByte[tTemp] = (byte)Convert.ToInt32(a, 16); // if (i == (tPinLen - 2)) // { // if (tTemp < 7) // { // for (int x = (tTemp + 1); x < 8; x++) // { // tByte[x] = (byte)0xff; // } // } // } // tTemp++; // i = i + 2; // } // } // else // { // for (int i = 0; i < tPinLen - 1; ) // { // string a; // a = aPin.Substring(i, 2); // tByte[tTemp] = (byte)Convert.ToInt32(a, 16); // if (i == (tPinLen - 3)) // { // string b = aPin.Substring(tPinLen - 1) + "F"; // tByte[tTemp + 1] = (byte)Convert.ToInt32(b, 16); // if ((tTemp + 1) < 7) // { // for (int x = (tTemp + 2); x < 8; x++) // { // tByte[x] = (byte)0xff; // } // } // } // tTemp++; // i = i + 2; // } // } // } // catch (Exception e) // { // log.Error("pin2PinBlock error" + e.Message); // } // return tByte; //} ///// <summary> ///// 获取卡号密码pinblock计算 ///// </summary> ///// <param name="aPin"></param> ///// <param name="aCardNO"></param> ///// <returns></returns> //public static byte[] pin2PinBlockWithCardNO(string aPin, string aCardNO) //{ // byte[] tPinByte = pin2PinBlock(aPin); // if (aCardNO.Length == 11) // { // aCardNO = "00" + aCardNO; // } // else if (aCardNO.Length == 12) // { // aCardNO = "0" + aCardNO; // } // byte[] tPanByte = formatPan(aCardNO); // byte[] tByte = new byte[8]; // for (int i = 0; i < 8; i++) // { // tByte[i] = (byte)(tPinByte[i] ^ tPanByte[i]); // } // return tByte; //} ///// <summary> ///// 卡号计算 ///// </summary> ///// <param name="aPan"></param> ///// <returns></returns> //private static byte[] formatPan(string aPan) //{ // int tPanLen = aPan.Length; // byte[] tByte = new byte[8]; // int temp = tPanLen - 13; // try // { // tByte[0] = (byte)0x00; // tByte[1] = (byte)0x00; // for (int i = 2; i < 8; i++) // { // string a = aPan.Substring(temp, 2).Trim(); // tByte[i] = (byte)Convert.ToInt32(a, 16); // temp = temp + 2; // } // } // catch (Exception e) // { // log.Error("formatPan error:" + e.Message); // } // return tByte; //} ///<summary> /// 加密 /// </summary> /// <returns></returns> private static byte[] encryptedData(byte[] encData) { try { IBufferedCipher c = CipherUtilities.GetCipher("RSA/NONE/PKCS1Padding"); c.Init(true, new ParametersWithRandom(CertUtil.GetEncryptKey(), new SecureRandom())); return(c.DoFinal(encData)); } catch (Exception e) { log.Error("encryptedData error: " + e.Message); return(new byte[0]); } }