public int Encrypt(MobilpayEncrypt mobilpayEncrypt) { try { byte[] bytes = Encoding.ASCII.GetBytes(mobilpayEncrypt.Data); Random random = new Random(); byte[] numArray = new byte[8]; for (int index = 0; index < numArray.Length; ++index) { numArray[index] = (byte)random.Next(0, (int)byte.MaxValue); } this.RC4(ref bytes, numArray); var publicKey = new X509Certificate2(mobilpayEncrypt.X509CertificateFilePath).GetRSAPublicKey(); //RSACng key = (RSACryptoServiceProvider)publicKey; publicKey.ExportParameters(false); byte[] inArray = publicKey.Encrypt(numArray, RSAEncryptionPadding.Pkcs1); mobilpayEncrypt.EncryptedData = Convert.ToBase64String(bytes); mobilpayEncrypt.EnvelopeKey = Convert.ToBase64String(inArray); } catch (CryptographicException ex) { throw ex; } return(0); }
public int BuildXmlEncrypt(Mobilpay_Payment_Request_Card card, MobilpayEncrypt mobilpayEncrypt) { try { string message = this.VerifyCardObject(card); if (message == "") { string xmlText = this.GetXmlText(card); mobilpayEncrypt.Data = xmlText; Encrypt(mobilpayEncrypt); return(0); } Exception exception = new Exception(message); return(-1); } catch (Exception ex) { throw ex; } }