Skip to content

Commit

Permalink
Dev (#10)
Browse files Browse the repository at this point in the history
+ Added `Signature` to `AsymmetricPublicKeySigningRequest`
+ Updated references
+ Included PDBs and source code into the NuGet packages
+ Casting refactored
+ `AsymmetricKeyBase.Export` and `AsymmetricKeyBase.Import`
+ Asynchronous PKI
+ `(Disposable)SignedPayload` extendable classes
+ `EncryptedValue` is now disposable
+ KDF options and `KdfAlgorithmBase.ValidateOptions`
+ Added display name for crypto algorithms
  • Loading branch information
nd1012 authored May 7, 2023
1 parent 9b5fa55 commit 945cab4
Show file tree
Hide file tree
Showing 101 changed files with 7,696 additions and 750 deletions.
35 changes: 9 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,16 @@ for performing a PFS key exchange:
```cs
// Peer creates a key pair (PFS or stored) and sends peerPublicKeyData to the provider
using IAsymmetricPrivateKey peerPrivateKey = AsymmetricHelper.CreateKeyExchangeKeyPair();
byte[] peerPublicKeyData;// Needs to be available at the provider
using(MemoryStream ms = new())
{
ms.WriteAny(peerPrivateKey.PublicKey);// Serialize the public key (the provider doesn't know the public key format yet)
peerPublicKeyData = ms.ToArray();
}
byte[] peerPublicKeyData = (byte[])peerPrivateKey.PublicKey;// Needs to be available at the provider
// Encryption at the provider (pfsKey shouldn't be stored and can be a new key for every cipher message)
using MemoryStream ms = new(peerPublicKeyData);
using IAsymmetricPublicKey peerPublicKey = ms.ReadAny<IAsymmetricPublicKey>();// Deserialize the peers public key of any format
using IAsymmetricPublicKey peerPublicKey = AsymmetricKeyBase.Import<IAsymmetricPublicKey>(peerPublicKeyData);// Deserialize the peers public key of any format
CryptoOptions options = EncryptionHelper.GetDefaultOptions();// Add the asymmetric key information for key pair creation
options.AsymmetricAlgorithm = peerPublicKey.Algorithm.Name;
options.AsymmetricKeyBits = peerPublicKey.Bits;
options.PublicKey = peerPublicKey;// Required for encrypting especially for the one specific peer
byte[] cipher;
using(IAsymmetricPrivateKey pfsKey = AsymmetricHelper.CreateKeyExchangeKeyPair(options))
using(IKeyExchangePrivateKey pfsKey = AsymmetricHelper.CreateKeyExchangeKeyPair(options))
cipher = raw.Encrypt(pfsKey, options);// Only the peer can decrypt the cipher after pfsKey was disposed
// Decryption at the peer
Expand Down Expand Up @@ -179,16 +173,10 @@ PFS example:
```cs
// A: Create a key pair
using IKeyExchangePrivateKey privateKeyA = AsymmetricHelper.CreateKeyExchangeKeyPair();
byte[] publicKeyData;// Needs to be available at B
using(MemoryStream ms = new())
{
ms.WriteAny(privateKeyA.PublicKey);// Serialize the public key (the provider doesn't know the public key format yet)
publicKeyData = ms.ToArray();
}
byte[] publicKeyData = (byte[])privateKeyA.PublicKey;// Needs to be available at B
// B: Create a key pair, key exchange data and derive the shared key
using MemoryStream ms = new(publicKeyData);
using IAsymmetricPublicKey publicKeyA = ms.ReadAny<IAsymmetricPublicKey>();// Deserialize the peers public key of any format
using IAsymmetricPublicKey publicKeyA = AsymmetricKeyBase.Import<IAsymmetricPublicKey>(publicKeyData);// Deserialize the peers public key of any format
using IKeyExchangePrivateKey privateKeyB = AsymmetricHelper.CreateKeyExchangeKeyPair(new()
{
AsymmetricAlgorithm = publicKeyA.Algorithm.Name,
Expand Down Expand Up @@ -359,20 +347,15 @@ which allows to
using ISignaturePrivateKey privateRootKey = AsymmetricHelper.CreateSignatureKeyPair();

// Self-sign the public root key
using AsymmetricSignedPublicKey signedPublicRootKey = new()
{
PublicKey = privateRootKey.PublicKey.GetCopy()
};
using AsymmetricSignedPublicKey signedPublicRootKey = new(privateRootKey.PublicKey);
signedPublicRootKey.Sign(privateRootKey);

// Create a key pair, which will be signed
// Create a key pair, which will be signed, and a signing request
using ISignaturePrivateKey privateKey = AsymmetricHelper.CreateSignatureKeyPair();
using AsymmetricPublicKeySigningRequest signingRequest = new(privateKey.PublicKey);

// Sign the public key
using AsymmetricSignedPublicKey signedPublicKey = new()
{
PublicKey = privateKey.PublicKey.GetCopy()
};
using AsymmetricSignedPublicKey signedPublicKey = signingRequest.GetAsUnsignedKey();
signedPublicKey.Sign(privateRootKey);

// Setup the PKI (minimal setup for signed public key validation)
Expand Down
15 changes: 15 additions & 0 deletions docs/api/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,21 @@
<li>
<a href="wan24.Crypto.AsymmetricSignedPublicKey.RootTrust_Delegate.html" name="" title="AsymmetricSignedPublicKey.RootTrust_Delegate">AsymmetricSignedPublicKey.RootTrust_Delegate</a>
</li>
<li>
<a href="wan24.Crypto.AsymmetricSignedPublicKey.RootTrustAsync_Delegate.html" name="" title="AsymmetricSignedPublicKey.RootTrustAsync_Delegate">AsymmetricSignedPublicKey.RootTrustAsync_Delegate</a>
</li>
<li>
<a href="wan24.Crypto.AsymmetricSignedPublicKey.SignedPublicKeyRevocation_Delegate.html" name="" title="AsymmetricSignedPublicKey.SignedPublicKeyRevocation_Delegate">AsymmetricSignedPublicKey.SignedPublicKeyRevocation_Delegate</a>
</li>
<li>
<a href="wan24.Crypto.AsymmetricSignedPublicKey.SignedPublicKeyRevocationAsync_Delegate.html" name="" title="AsymmetricSignedPublicKey.SignedPublicKeyRevocationAsync_Delegate">AsymmetricSignedPublicKey.SignedPublicKeyRevocationAsync_Delegate</a>
</li>
<li>
<a href="wan24.Crypto.AsymmetricSignedPublicKey.SignedPublicKeyStore_Delegate.html" name="" title="AsymmetricSignedPublicKey.SignedPublicKeyStore_Delegate">AsymmetricSignedPublicKey.SignedPublicKeyStore_Delegate</a>
</li>
<li>
<a href="wan24.Crypto.AsymmetricSignedPublicKey.SignedPublicKeyStoreAsync_Delegate.html" name="" title="AsymmetricSignedPublicKey.SignedPublicKeyStoreAsync_Delegate">AsymmetricSignedPublicKey.SignedPublicKeyStoreAsync_Delegate</a>
</li>
<li>
<a href="wan24.Crypto.CryptoAlgorithmBase.html" name="" title="CryptoAlgorithmBase">CryptoAlgorithmBase</a>
</li>
Expand Down Expand Up @@ -95,6 +104,9 @@
<li>
<a href="wan24.Crypto.DecryptionStreams.html" name="" title="DecryptionStreams">DecryptionStreams</a>
</li>
<li>
<a href="wan24.Crypto.DisposableSignedPayload-1.html" name="" title="DisposableSignedPayload&lt;T&gt;">DisposableSignedPayload&lt;T&gt;</a>
</li>
<li>
<a href="wan24.Crypto.EllipticCurves.html" name="" title="EllipticCurves">EllipticCurves</a>
</li>
Expand Down Expand Up @@ -233,6 +245,9 @@
<li>
<a href="wan24.Crypto.SignatureContainer.html" name="" title="SignatureContainer">SignatureContainer</a>
</li>
<li>
<a href="wan24.Crypto.SignedPayload-1.html" name="" title="SignedPayload&lt;T&gt;">SignedPayload&lt;T&gt;</a>
</li>
<li>
<a href="wan24.Crypto.X509Extensions.html" name="" title="X509Extensions">X509Extensions</a>
</li>
Expand Down
Loading

0 comments on commit 945cab4

Please sign in to comment.