Information: C # PKCS7 encryption and decryption
// encrypted string public String Encryption ( String TOE) { // encryption and decryption must use the same key, specific to fill out, but must be a 32-bit byte [] = keyArray UTF8Encoding.UTF8.GetBytes ( " 12345678123456781234567812345678 " ); RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Key = keyArray; rijndaelManaged.Mode = CipherMode.ECB; rijndaelManaged.Padding = PaddingMode.PKCS7; ICryptoTransform icryptoTransform = rijndaelManaged.CreateEncryptor(); byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toE); byte[] resultArray = icryptoTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return Convert.ToBase64String( resultArray, 0, resultArray.Length); } // decryption string public String Decryption ( String TOD) { // encryption and decryption must use the same key, fill their own specific value, but must be a 32-bit byte [] = keyArray UTF8Encoding.UTF8.GetBytes ( " 12345678123456781234567812345678 " ); RijndaelManaged rijndaelManaged = new RijndaelManaged(); rijndaelManaged.Key = keyArray; rijndaelManaged.Mode = CipherMode.ECB; rijndaelManaged.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = rijndaelManaged.CreateDecryptor(); byte[] toEncryptArray = Convert.FromBase64String(toD); byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return UTF8Encoding.UTF8.GetString(resultArray); }
-------------------------------------------------------------------
Reference: C # And the Java 3DES encryption mode ECB / PKCS7
Also we need to look carefully, looking not in line with data
References: How to achieve in Java PKCS7 encryption functions in C # inside?
Profile Address: https: //bbs.csdn.net/topics/340147880
One
/// <Summary> /// to create a signature /// </ Summary> /// <param name = "Data"> tag data </ param> /// <Returns> </ Returns> Private static byte [] CreateSign ( byte [] Data) { IF (Data == null ) the throw new new ArgumentNullException The ( " Data not empty " ); X509Certificate2 userCert = CreateCertificate(ConfigInfo.certFileName,ConfigInfo.Password); if (userCert == null) throw new ArgumentNullException("证书不能为空"); Content the ContentInfo = new new the ContentInfo (Data); // set the data to be signed SignedCms SignedCms = new new SignedCms (Content); CmsSigner signer = new CmsSigner(userCert); try { signedCms.ComputeSignature (Signer); // create a signature return signedCms.Encode (); } catch (CryptographicException ex) { throw ex; } }
two
/// <the Summary> /// Create a certificate /// </ the Summary> /// <param name = "fileName"> File name </ param> /// <param name = "password"> Password </ param > /// <Returns> </ Returns> public static an X509Certificate2 CreateCertificate ( String fileName, String password) { if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(password)) { return null; } try { return new X509Certificate2(fileName, password, X509KeyStorageFlags.Exportable); } catch (CryptographicException ex) { throw ex; } }
three
/// <Summary> /// verify the signature /// </ Summary> /// <param name = "Signature"> tag data </ param> /// <param name = "Certificate"> certificate </ param> /// <Returns> </ Returns> public static BOOL the Verify ( byte [] Signature, byte [] Data) { ContentInfo contentInfo = new ContentInfo(data); SignedCms verifyCms = new SignedCms(contentInfo,true); try { verifyCms.Decode(signature); verifyCms.CheckSignature(true); return true; } catch (CryptographicException ex) { ServiceHub.AddLog (RuntimeLogType.Exception, null , " signature decoding failure: " + ex.Message, ex.StackTrace); the throw EX; } }
--------------------------------------------------
Reference: seeking a big God help write a JAVA method signature corresponding to the C # language
Profile Address: https: //bbs.csdn.net/topics/392437375
Reference: RSA encryption and decryption, Java and C # interoperability
Profile Address: https: //blog.csdn.net/thc1987/article/details/81383365
It is important to look at.