public static byte[] RsaPkcs15Sha_Decrypt( ArraySegment <byte> data, X509Certificate2 cert, RSA rsaPrivate, SecurityPolicy policy) { int cipherTextBlockSize = UASecurity.GetCipherTextBlockSize(cert); byte[] buffer1 = new byte[data.Count / cipherTextBlockSize * UASecurity.GetPlainBlockSize(cert, UASecurity.UseOaepForSecurityPolicy(policy))]; int length = rsaPrivate.KeySize / 8; UASecurity.GetPlainBlockSize(cert, UASecurity.UseOaepForSecurityPolicy(policy)); if ((uint)(data.Count % length) > 0U) { throw new Exception(string.Format("Input data is not a multiple of block size, {0}/{1}", data.Count, length)); } MemoryStream memoryStream = new MemoryStream(buffer1); byte[] data1 = new byte[length]; for (int offset = data.Offset; offset < data.Offset + data.Count; offset += length) { Array.Copy(data.Array, offset, data1, 0, data1.Length); byte[] buffer2 = rsaPrivate.Decrypt(data1, UASecurity.UseOaepForSecurityPolicy(policy)); memoryStream.Write(buffer2, 0, buffer2.Length); } memoryStream.Close(); return(buffer1); }