本文整理汇总了C#中MimeEntity类的典型用法代码示例。如果您正苦于以下问题:C# MimeEntity类的具体用法?C# MimeEntity怎么用?C# MimeEntity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MimeEntity类属于命名空间,在下文中一共展示了MimeEntity类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: PrepareEntityForEncrypting
static void PrepareEntityForEncrypting (MimeEntity entity)
{
if (entity is Multipart) {
// Note: we do not want to modify multipart/signed parts
if (entity is MultipartSigned)
return;
var multipart = (Multipart) entity;
foreach (var subpart in multipart)
PrepareEntityForEncrypting (subpart);
} else if (entity is MessagePart) {
var mpart = (MessagePart) entity;
if (mpart.Message != null && mpart.Message.Body != null)
PrepareEntityForEncrypting (mpart.Message.Body);
} else {
var part = (MimePart) entity;
if (part.ContentTransferEncoding == ContentEncoding.Binary)
part.ContentTransferEncoding = ContentEncoding.Base64;
else if (part.ContentTransferEncoding != ContentEncoding.Base64)
part.ContentTransferEncoding = ContentEncoding.QuotedPrintable;
}
}
开发者ID:richard2753,项目名称:MimeKit,代码行数:25,代码来源:MultipartEncrypted.cs
示例2: PrepareEntityForSigning
static void PrepareEntityForSigning (MimeEntity entity)
{
if (entity is Multipart) {
// Note: we do not want to modify multipart/signed parts
if (entity is MultipartSigned)
return;
var multipart = (Multipart) entity;
foreach (var subpart in multipart)
PrepareEntityForSigning (subpart);
} else if (entity is MessagePart) {
var mpart = (MessagePart) entity;
if (mpart.Message != null && mpart.Message.Body != null)
PrepareEntityForSigning (mpart.Message.Body);
} else {
var part = (MimePart) entity;
switch (part.ContentTransferEncoding) {
case ContentEncoding.SevenBit:
// need to make sure that "From "-lines are properly armored
part.ContentTransferEncoding = part.GetBestEncoding (EncodingConstraint.SevenBit);
break;
case ContentEncoding.EightBit:
part.ContentTransferEncoding = ContentEncoding.QuotedPrintable;
break;
case ContentEncoding.Binary:
part.ContentTransferEncoding = ContentEncoding.Base64;
break;
}
}
}
开发者ID:gphummer,项目名称:MimeKit,代码行数:33,代码来源:MultipartSigned.cs
示例3: GetMimeEntityHeader
/// <summary>
/// Gets specified mime entity header.
/// Note: Header terminator blank line is included.
/// </summary>
/// <param name="entity">Mime entity.</param>
/// <returns></returns>
public static byte[] GetMimeEntityHeader(MimeEntity entity)
{
return Encoding.ASCII.GetBytes(entity.HeaderString + "\r\n");
}
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:10,代码来源:_FetchHelper.cs
示例4: Create
/// <summary>
/// Creates a new <see cref="MultipartSigned"/>.
/// </summary>
/// <remarks>
/// Cryptographically signs the entity using the supplied signer in order
/// to generate a detached signature and then adds the entity along with
/// the detached signature data to a new multipart/signed part.
/// </remarks>
/// <returns>A new <see cref="MultipartSigned"/> instance.</returns>
/// <param name="ctx">The S/MIME context to use for signing.</param>
/// <param name="signer">The signer.</param>
/// <param name="entity">The entity to sign.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="ctx"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="signer"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public static MultipartSigned Create (SecureMimeContext ctx, CmsSigner signer, MimeEntity entity)
{
if (ctx == null)
throw new ArgumentNullException ("ctx");
if (signer == null)
throw new ArgumentNullException ("signer");
if (entity == null)
throw new ArgumentNullException ("entity");
PrepareEntityForSigning (entity);
using (var memory = new MemoryBlockStream ()) {
using (var filtered = new FilteredStream (memory)) {
// Note: see rfc3156, section 3 - second note
filtered.Add (new ArmoredFromFilter ());
// Note: see rfc3156, section 5.4 (this is the main difference between rfc2015 and rfc3156)
filtered.Add (new TrailingWhitespaceFilter ());
// Note: see rfc2015 or rfc3156, section 5.1
filtered.Add (new Unix2DosFilter ());
entity.WriteTo (filtered);
filtered.Flush ();
}
memory.Position = 0;
// Note: we need to parse the modified entity structure to preserve any modifications
var parser = new MimeParser (memory, MimeFormat.Entity);
var parsed = parser.ParseEntity ();
memory.Position = 0;
// sign the cleartext content
var micalg = ctx.GetDigestAlgorithmName (signer.DigestAlgorithm);
var signature = ctx.Sign (signer, memory);
var signed = new MultipartSigned ();
// set the protocol and micalg Content-Type parameters
signed.ContentType.Parameters["protocol"] = ctx.SignatureProtocol;
signed.ContentType.Parameters["micalg"] = micalg;
// add the modified/parsed entity as our first part
signed.Add (parsed);
// add the detached signature as the second part
signed.Add (signature);
return signed;
}
}
开发者ID:gphummer,项目名称:MimeKit,代码行数:75,代码来源:MultipartSigned.cs
示例5: ConstructParts
/// <summary>
/// Constructs specified entity and it's childentities bodystructure string.
/// </summary>
/// <param name="entity">Mime entity.</param>
/// <param name="bodystructure">Specifies if to construct BODY or BODYSTRUCTURE.</param>
/// <returns></returns>
private static string ConstructParts(MimeEntity entity, bool bodystructure)
{
/* RFC 3501 7.4.2 BODYSTRUCTURE
BODY A form of BODYSTRUCTURE without extension data.
A parenthesized list that describes the [MIME-IMB] body
structure of a message. This is computed by the server by
parsing the [MIME-IMB] header fields, defaulting various fields
as necessary.
For example, a simple text message of 48 lines and 2279 octets
can have a body structure of: ("TEXT" "PLAIN" ("CHARSET"
"US-ASCII") NIL NIL "7BIT" 2279 48)
Multiple parts are indicated by parenthesis nesting. Instead
of a body type as the first element of the parenthesized list,
there is a sequence of one or more nested body structures. The
second element of the parenthesized list is the multipart
subtype (mixed, digest, parallel, alternative, etc.).
For example, a two part message consisting of a text and a
BASE64-encoded text attachment can have a body structure of:
(("TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 1152
23)("TEXT" "PLAIN" ("CHARSET" "US-ASCII" "NAME" "cc.diff")
"<[email protected]>" "Compiler diff"
"BASE64" 4554 73) "MIXED")
Extension data follows the multipart subtype. Extension data
is never returned with the BODY fetch, but can be returned with
a BODYSTRUCTURE fetch. Extension data, if present, MUST be in
the defined order. The extension data of a multipart body part
are in the following order:
body parameter parenthesized list
A parenthesized list of attribute/value pairs [e.g., ("foo"
"bar" "baz" "rag") where "bar" is the value of "foo", and
"rag" is the value of "baz"] as defined in [MIME-IMB].
body disposition
A parenthesized list, consisting of a disposition type
string, followed by a parenthesized list of disposition
attribute/value pairs as defined in [DISPOSITION].
body language
A string or parenthesized list giving the body language
value as defined in [LANGUAGE-TAGS].
body location
A string list giving the body content URI as defined in [LOCATION].
Any following extension data are not yet defined in this
version of the protocol. Such extension data can consist of
zero or more NILs, strings, numbers, or potentially nested
parenthesized lists of such data. Client implementations that
do a BODYSTRUCTURE fetch MUST be prepared to accept such
extension data. Server implementations MUST NOT send such
extension data until it has been defined by a revision of this
protocol.
The basic fields of a non-multipart body part are in the
following order:
body type
A string giving the content media type name as defined in [MIME-IMB].
body subtype
A string giving the content subtype name as defined in [MIME-IMB].
body parameter parenthesized list
A parenthesized list of attribute/value pairs [e.g., ("foo"
"bar" "baz" "rag") where "bar" is the value of "foo" and
"rag" is the value of "baz"] as defined in [MIME-IMB].
body id
A string giving the content id as defined in [MIME-IMB].
body description
A string giving the content description as defined in [MIME-IMB].
body encoding
A string giving the content transfer encoding as defined in [MIME-IMB].
body size
A number giving the size of the body in octets. Note that
this size is the size in its transfer encoding and not the
resulting size after any decoding.
A body type of type MESSAGE and subtype RFC822 contains,
immediately after the basic fields, the envelope structure,
body structure, and size in text lines of the encapsulated
message.
A body type of type TEXT contains, immediately after the basic
fields, the size of the body in text lines. Note that this
//.........这里部分代码省略.........
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:101,代码来源:IMAP_BODY.cs
示例6: Create
/// <summary>
/// Creates a new <see cref="MultipartEncrypted"/>.
/// </summary>
/// <remarks>
/// Encrypts the entity to the specified recipients, encapsulating the result in a
/// new multipart/encrypted part.
/// </remarks>
/// <returns>A new <see cref="MimeKit.Cryptography.MultipartEncrypted"/> instance containing
/// the encrypted version of the specified entity.</returns>
/// <param name="recipients">The recipients for the encrypted entity.</param>
/// <param name="entity">The entity to sign and encrypt.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="recipients"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// One or more of the recipient keys cannot be used for encrypting.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// A default <see cref="OpenPgpContext"/> has not been registered.
/// </exception>
public static MultipartEncrypted Create (IEnumerable<PgpPublicKey> recipients, MimeEntity entity)
{
if (recipients == null)
throw new ArgumentNullException ("recipients");
if (entity == null)
throw new ArgumentNullException ("entity");
using (var ctx = (OpenPgpContext) CryptographyContext.Create ("application/pgp-encrypted")) {
return Create (ctx, recipients, entity);
}
}
开发者ID:richard2753,项目名称:MimeKit,代码行数:34,代码来源:MultipartEncrypted.cs
示例7: SignAndEncrypt
/// <summary>
/// Cryptographically signs and encrypts the specified entity.
/// </summary>
/// <remarks>
/// Cryptographically signs entity using the supplied signer and then
/// encrypts the result to the specified recipients.
/// </remarks>
/// <returns>The signed and encrypted entity.</returns>
/// <param name="signer">The signer.</param>
/// <param name="digestAlgo">The digest algorithm to use for signing.</param>
/// <param name="recipients">The recipients.</param>
/// <param name="entity">The entity.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="signer"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="recipients"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="CertificateNotFoundException">
/// <para>A signing certificate could not be found for <paramref name="signer"/>.</para>
/// <para>-or-</para>
/// <para>A certificate could not be found for one or more of the <paramref name="recipients"/>.</para>
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public static ApplicationPkcs7Mime SignAndEncrypt (MailboxAddress signer, DigestAlgorithm digestAlgo, IEnumerable<MailboxAddress> recipients, MimeEntity entity)
{
if (signer == null)
throw new ArgumentNullException ("signer");
if (recipients == null)
throw new ArgumentNullException ("recipients");
if (entity == null)
throw new ArgumentNullException ("entity");
using (var ctx = (SecureMimeContext) CryptographyContext.Create ("application/pkcs7-mime")) {
return SignAndEncrypt (ctx, signer, digestAlgo, recipients, entity);
}
}
开发者ID:naeemkhedarun,项目名称:MimeKit,代码行数:42,代码来源:ApplicationPkcs7Mime.cs
示例8: Verify
/// <summary>
/// Verifies the signed-data and returns the unencapsulated <see cref="MimeKit.MimeEntity"/>.
/// </summary>
/// <remarks>
/// Verifies the signed-data and returns the unencapsulated <see cref="MimeKit.MimeEntity"/>.
/// </remarks>
/// <returns>The list of digital signatures.</returns>
/// <param name="entity">The unencapsulated entity.</param>
/// <exception cref="System.InvalidOperationException">
/// The "smime-type" parameter on the Content-Type header is not "signed-data".
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public DigitalSignatureCollection Verify (out MimeEntity entity)
{
using (var ctx = (SecureMimeContext) CryptographyContext.Create ("application/pkcs7-mime")) {
return Verify (ctx, out entity);
}
}
开发者ID:naeemkhedarun,项目名称:MimeKit,代码行数:20,代码来源:ApplicationPkcs7Mime.cs
示例9: Sign
/// <summary>
/// Cryptographically signs the specified entity.
/// </summary>
/// <remarks>
/// <para>Signs the entity using the supplied signer, digest algorithm and the default
/// <see cref="SecureMimeContext"/>.</para>
/// <para>For better interoperability with other mail clients, you should use
/// <see cref="MultipartSigned.Create(SecureMimeContext, CmsSigner, MimeEntity)"/>
/// instead as the multipart/signed format is supported among a much larger
/// subset of mail client software.</para>
/// </remarks>
/// <returns>The signed entity.</returns>
/// <param name="signer">The signer.</param>
/// <param name="digestAlgo">The digest algorithm to use for signing.</param>
/// <param name="entity">The entity.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="signer"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="CertificateNotFoundException">
/// A signing certificate could not be found for <paramref name="signer"/>.
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public static ApplicationPkcs7Mime Sign (MailboxAddress signer, DigestAlgorithm digestAlgo, MimeEntity entity)
{
if (signer == null)
throw new ArgumentNullException (nameof (signer));
if (entity == null)
throw new ArgumentNullException (nameof (entity));
using (var ctx = (SecureMimeContext) CryptographyContext.Create ("application/pkcs7-mime")) {
return Sign (ctx, signer, digestAlgo, entity);
}
}
开发者ID:surekqomi,项目名称:MimeKit,代码行数:38,代码来源:ApplicationPkcs7Mime.cs
示例10: Encrypt
/// <summary>
/// Encrypts the specified entity.
/// </summary>
/// <remarks>
/// Encrypts the entity to the specified recipients using the default <see cref="SecureMimeContext"/>.
/// </remarks>
/// <returns>The encrypted entity.</returns>
/// <param name="recipients">The recipients.</param>
/// <param name="entity">The entity.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="recipients"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public static ApplicationPkcs7Mime Encrypt (CmsRecipientCollection recipients, MimeEntity entity)
{
if (recipients == null)
throw new ArgumentNullException (nameof (recipients));
if (entity == null)
throw new ArgumentNullException (nameof (entity));
using (var ctx = (SecureMimeContext) CryptographyContext.Create ("application/pkcs7-mime")) {
return Encrypt (ctx, recipients, entity);
}
}
开发者ID:surekqomi,项目名称:MimeKit,代码行数:29,代码来源:ApplicationPkcs7Mime.cs
示例11: ParseHeaderFields
/// <summary>
/// Returns requested header fields lines.
/// Note: Header terminator blank line is included.
/// </summary>
/// <param name="fieldsStr">Header fields to get.</param>
/// <param name="entity">Entity which header field lines to get.</param>
/// <returns></returns>
public static byte[] ParseHeaderFields(string fieldsStr, MimeEntity entity)
{
return ParseHeaderFields(fieldsStr, Encoding.Default.GetBytes(entity.HeaderString));
}
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:11,代码来源:_FetchHelper.cs
示例12: Compress
/// <summary>
/// Compresses the specified entity.
/// </summary>
/// <remarks>
/// <para>Compresses the specified entity using the specified <see cref="SecureMimeContext"/>.</para>
/// <para>It should be noted that this feature is not supported by most mail clients,
/// even among those that support S/MIME.</para>
/// </remarks>
/// <returns>The compressed entity.</returns>
/// <param name="ctx">The S/MIME context to use for compressing.</param>
/// <param name="entity">The entity.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="ctx"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public static ApplicationPkcs7Mime Compress (SecureMimeContext ctx, MimeEntity entity)
{
if (ctx == null)
throw new ArgumentNullException ("ctx");
if (entity == null)
throw new ArgumentNullException ("entity");
using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
options.NewLineFormat = NewLineFormat.Dos;
entity.WriteTo (options, memory);
memory.Position = 0;
return ctx.Compress (memory);
}
}
开发者ID:naeemkhedarun,项目名称:MimeKit,代码行数:37,代码来源:ApplicationPkcs7Mime.cs
示例13: Encrypt
/// <summary>
/// Encrypts the specified entity.
/// </summary>
/// <remarks>
/// Encrypts the entity to the specified recipients using the supplied <see cref="SecureMimeContext"/>.
/// </remarks>
/// <returns>The encrypted entity.</returns>
/// <param name="ctx">The S/MIME context to use for encrypting.</param>
/// <param name="recipients">The recipients.</param>
/// <param name="entity">The entity.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="ctx"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="recipients"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// Valid certificates could not be found for one or more of the <paramref name="recipients"/>.
/// </exception>
/// <exception cref="CertificateNotFoundException">
/// A certificate could not be found for one or more of the <paramref name="recipients"/>.
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public static ApplicationPkcs7Mime Encrypt (SecureMimeContext ctx, IEnumerable<MailboxAddress> recipients, MimeEntity entity)
{
if (ctx == null)
throw new ArgumentNullException ("ctx");
if (recipients == null)
throw new ArgumentNullException ("recipients");
if (entity == null)
throw new ArgumentNullException ("entity");
using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
options.NewLineFormat = NewLineFormat.Dos;
entity.WriteTo (options, memory);
memory.Position = 0;
return (ApplicationPkcs7Mime) ctx.Encrypt (recipients, memory);
}
}
开发者ID:naeemkhedarun,项目名称:MimeKit,代码行数:47,代码来源:ApplicationPkcs7Mime.cs
示例14: Sign
/// <summary>
/// Cryptographically signs the specified entity.
/// </summary>
/// <remarks>
/// <para>Signs the entity using the supplied signer.</para>
/// <para>For better interoperability with other mail clients, you should use
/// <see cref="MultipartSigned.Create(SecureMimeContext, CmsSigner, MimeEntity)"/>
/// instead as the multipart/signed format is supported among a much larger
/// subset of mail client software.</para>
/// </remarks>
/// <returns>The signed entity.</returns>
/// <param name="signer">The signer.</param>
/// <param name="entity">The entity.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="signer"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public static ApplicationPkcs7Mime Sign (CmsSigner signer, MimeEntity entity)
{
if (signer == null)
throw new ArgumentNullException ("signer");
if (entity == null)
throw new ArgumentNullException ("entity");
using (var ctx = (SecureMimeContext) CryptographyContext.Create ("application/pkcs7-mime")) {
return Sign (ctx, signer, entity);
}
}
开发者ID:naeemkhedarun,项目名称:MimeKit,代码行数:33,代码来源:ApplicationPkcs7Mime.cs
示例15: Verify
/// <summary>
/// Verify the digital signatures of the specified signedData and extract the original content.
/// </summary>
/// <returns>The list of digital signatures.</returns>
/// <param name="signedData">The signed data.</param>
/// <param name="entity">The unencapsulated entity.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="signedData"/> is <c>null</c>.
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public DigitalSignatureCollection Verify(Stream signedData, out MimeEntity entity)
{
if (signedData == null)
throw new ArgumentNullException ("signedData");
var parser = new CmsSignedDataParser (signedData);
var signed = parser.GetSignedContent ();
entity = MimeEntity.Load (signed.ContentStream);
return GetDigitalSignatures (parser);
}
开发者ID:princeoffoods,项目名称:MimeKit,代码行数:24,代码来源:SecureMimeContext.cs
示例16: SignAndEncrypt
/// <summary>
/// Create a multipart/encrypted MIME part by signing and encrypting the specified entity.
/// </summary>
/// <remarks>
/// Signs the entity using the supplied signer and digest algorithm and then encrypts to
/// the specified recipients, encapsulating the result in a new multipart/encrypted part.
/// </remarks>
/// <returns>A new <see cref="MultipartEncrypted"/> instance containing
/// the signed and encrypted version of the specified entity.</returns>
/// <param name="ctx">The OpenPGP cryptography context to use for signing and encrypting.</param>
/// <param name="signer">The signer to use to sign the entity.</param>
/// <param name="digestAlgo">The digest algorithm to use for signing.</param>
/// <param name="recipients">The recipients for the encrypted entity.</param>
/// <param name="entity">The entity to sign and encrypt.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="ctx"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="signer"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="recipients"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="PrivateKeyNotFoundException">
/// The private key for <paramref name="signer"/> could not be found.
/// </exception>
/// <exception cref="PublicKeyNotFoundException">
/// A public key for one or more of the <paramref name="recipients"/> could not be found.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The user chose to cancel the password prompt.
/// </exception>
/// <exception cref="System.UnauthorizedAccessException">
/// 3 bad attempts were made to unlock the secret key.
/// </exception>
public static MultipartEncrypted SignAndEncrypt (OpenPgpContext ctx, MailboxAddress signer, DigestAlgorithm digestAlgo, IEnumerable<MailboxAddress> recipients, MimeEntity entity)
{
if (ctx == null)
throw new ArgumentNullException (nameof (ctx));
if (signer == null)
throw new ArgumentNullException (nameof (signer));
if (recipients == null)
throw new ArgumentNullException (nameof (recipients));
if (entity == null)
throw new ArgumentNullException (nameof (entity));
using (var memory = new MemoryBlockStream ()) {
var options = FormatOptions.CloneDefault ();
options.NewLineFormat = NewLineFormat.Dos;
entity.WriteTo (options, memory);
memory.Position = 0;
var encrypted = new MultipartEncrypted ();
encrypted.ContentType.Parameters["protocol"] = ctx.EncryptionProtocol;
// add the protocol version part
encrypted.Add (new ApplicationPgpEncrypted ());
// add the encrypted entity as the second part
encrypted.Add (ctx.SignAndEncrypt (signer, digestAlgo, recipients, memory));
return encrypted;
}
}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:68,代码来源:MultipartEncrypted.cs
注:本文中的MimeEntity类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论