Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crypto/src/cms/CMSAttributeTableGenerationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Org.BouncyCastle.Cms
{
/// <summary>Exception thrown when a CMS signed or authenticated attribute table cannot be generated.</summary>
[Serializable]
public class CmsAttributeTableGenerationException
: CmsException
Expand Down
1 change: 1 addition & 0 deletions crypto/src/cms/CMSException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Org.BouncyCastle.Cms
{
/// <summary>General exception thrown when CMS processing fails.</summary>
[Serializable]
public class CmsException
: Exception
Expand Down
21 changes: 21 additions & 0 deletions crypto/src/cms/CMSPBEKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

namespace Org.BouncyCastle.Cms
{
/// <summary>
/// Base class for password-based keys used with CMS enveloped-data recipients. Passed to
/// <see cref="CmsEnvelopedGenerator.AddPasswordRecipient"/>.
/// </summary>
public abstract class CmsPbeKey
// TODO Create an equivalent interface somewhere?
// : PBEKey
Expand All @@ -20,6 +24,10 @@ public abstract class CmsPbeKey
internal readonly byte[] salt;
internal readonly int iterationCount;

/// <summary>Creates a PBE key from explicit password, salt, and iteration count.</summary>
/// <param name="password">The password characters.</param>
/// <param name="salt">The PBKDF2 salt.</param>
/// <param name="iterationCount">The PBKDF2 iteration count.</param>
public CmsPbeKey(
char[] password,
byte[] salt,
Expand All @@ -30,6 +38,10 @@ public CmsPbeKey(
this.iterationCount = iterationCount;
}

/// <summary>Creates a PBE key from a password and PBKDF2 AlgorithmIdentifier.</summary>
/// <param name="password">The password characters.</param>
/// <param name="keyDerivationAlgorithm">The PBKDF2 algorithm identifier.</param>
/// <exception cref="ArgumentException">The key derivation algorithm is not PBKDF2.</exception>
public CmsPbeKey(
char[] password,
AlgorithmIdentifier keyDerivationAlgorithm)
Expand All @@ -49,13 +61,16 @@ public CmsPbeKey(
}

#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
/// <summary>Creates a PBE key from explicit password, salt, and iteration count.</summary>
public CmsPbeKey(ReadOnlySpan<char> password, ReadOnlySpan<byte> salt, int iterationCount)
{
this.password = password.ToArray();
this.salt = salt.ToArray();
this.iterationCount = iterationCount;
}

/// <summary>Creates a PBE key from a password and PBKDF2 AlgorithmIdentifier.</summary>
/// <exception cref="ArgumentException">The key derivation algorithm is not PBKDF2.</exception>
public CmsPbeKey(ReadOnlySpan<char> password, AlgorithmIdentifier keyDerivationAlgorithm)
{
if (!keyDerivationAlgorithm.Algorithm.Equals(PkcsObjectIdentifiers.IdPbkdf2))
Expand All @@ -79,26 +94,32 @@ public CmsPbeKey(ReadOnlySpan<char> password, AlgorithmIdentifier keyDerivationA
Arrays.ZeroMemory(this.password);
}

/// <summary>Gets a copy of the PBKDF2 salt.</summary>
public byte[] Salt
{
get { return Arrays.Clone(salt); }
}

/// <summary>Gets the PBKDF2 iteration count.</summary>
public int IterationCount
{
get { return iterationCount; }
}

/// <summary>Gets the key algorithm name (<c>PKCS5S2</c>).</summary>
public string Algorithm
{
get { return "PKCS5S2"; }
}

/// <summary>Gets the encoding format name (<c>RAW</c>).</summary>
public string Format
{
get { return "RAW"; }
}

/// <summary>Returns null; raw encoding is not supported.</summary>
/// <returns>Always null.</returns>
public byte[] GetEncoded()
{
return null;
Expand Down
1 change: 1 addition & 0 deletions crypto/src/cms/CMSStreamException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Org.BouncyCastle.Cms
{
/// <summary>Exception thrown when CMS streaming operations fail.</summary>
[Serializable]
public class CmsStreamException
: IOException
Expand Down
1 change: 1 addition & 0 deletions crypto/src/cms/CmsAlgorithmNotAllowedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Org.BouncyCastle.Cms
{
/// <summary>Exception thrown when a CMS operation does not permit the requested algorithm.</summary>
[Serializable]
public class CmsAlgorithmNotAllowedException
: CmsException
Expand Down
1 change: 1 addition & 0 deletions crypto/src/cms/CmsTagLengthException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Org.BouncyCastle.Cms
{
/// <summary>Exception thrown when an authenticated CMS content tag length is invalid.</summary>
[Serializable]
public class CmsTagLengthException
: CmsException
Expand Down
1 change: 1 addition & 0 deletions crypto/src/cms/CmsVerifierCertificateNotValidException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Org.BouncyCastle.Cms
{
/// <summary>Exception thrown when a signer certificate is not valid at the signing time.</summary>
[Serializable]
public class CmsVerifierCertificateNotValidException
: CmsException
Expand Down
8 changes: 5 additions & 3 deletions crypto/src/cms/PKCS5Scheme2PBEKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

namespace Org.BouncyCastle.Cms
{
/// <summary>
/// PKCS5 scheme-2 - password converted to bytes assuming ASCII.
/// </summary>
/// <summary>PKCS#5 scheme 2 PBE key with the password encoded as ASCII bytes.</summary>
public class Pkcs5Scheme2PbeKey
: CmsPbeKey
{
/// <inheritdoc/>
public Pkcs5Scheme2PbeKey(
char[] password,
byte[] salt,
Expand All @@ -22,6 +21,7 @@ public Pkcs5Scheme2PbeKey(
{
}

/// <inheritdoc/>
public Pkcs5Scheme2PbeKey(
char[] password,
AlgorithmIdentifier keyDerivationAlgorithm)
Expand All @@ -30,11 +30,13 @@ public Pkcs5Scheme2PbeKey(
}

#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
/// <inheritdoc/>
public Pkcs5Scheme2PbeKey(ReadOnlySpan<char> password, ReadOnlySpan<byte> salt, int iterationCount)
: base(password, salt, iterationCount)
{
}

/// <inheritdoc/>
public Pkcs5Scheme2PbeKey(ReadOnlySpan<char> password, AlgorithmIdentifier keyDerivationAlgorithm)
: base(password, keyDerivationAlgorithm)
{
Expand Down
8 changes: 5 additions & 3 deletions crypto/src/cms/PKCS5Scheme2UTF8PBEKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

namespace Org.BouncyCastle.Cms
{
/**
* PKCS5 scheme-2 - password converted to bytes using UTF-8.
*/
/// <summary>PKCS#5 scheme 2 PBE key with the password encoded as UTF-8 bytes.</summary>
public class Pkcs5Scheme2Utf8PbeKey
: CmsPbeKey
{
/// <inheritdoc/>
public Pkcs5Scheme2Utf8PbeKey(
char[] password,
byte[] salt,
Expand All @@ -22,6 +21,7 @@ public Pkcs5Scheme2Utf8PbeKey(
{
}

/// <inheritdoc/>
public Pkcs5Scheme2Utf8PbeKey(
char[] password,
AlgorithmIdentifier keyDerivationAlgorithm)
Expand All @@ -30,11 +30,13 @@ public Pkcs5Scheme2Utf8PbeKey(
}

#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
/// <inheritdoc/>
public Pkcs5Scheme2Utf8PbeKey(ReadOnlySpan<char> password, ReadOnlySpan<byte> salt, int iterationCount)
: base(password, salt, iterationCount)
{
}

/// <inheritdoc/>
public Pkcs5Scheme2Utf8PbeKey(ReadOnlySpan<char> password, AlgorithmIdentifier keyDerivationAlgorithm)
: base(password, keyDerivationAlgorithm)
{
Expand Down