Skip to content

Commit

Permalink
Updated examples to reflect new method shapes. Downgraded package to …
Browse files Browse the repository at this point in the history
….net 6 instead of .net 8 per review suggestion.

Signed-off-by: Whit Waldo <[email protected]>
  • Loading branch information
WhitWaldo committed Jan 3, 2024
1 parent 653436b commit 6fc560d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/Client/Cryptography/Cryptography.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ public override async Task RunAsync(CancellationToken cancellationToken)
//Encrypt the file
await using var encryptFs = new FileStream(fileName, FileMode.Open);
#pragma warning disable CS0618 // Type or member is obsolete
var encryptedBytesResult = await client.EncryptAsync(componentName, encryptFs, KeyWrapAlgorithm.Rsa, keyName,
DataEncryptionCipher.AesGcm, cancellationToken);
var encryptedBytesResult = await client.EncryptAsync(componentName, encryptFs, keyName, new EncryptionOptions(KeyWrapAlgorithm.Rsa)
{
EncryptionCipher = DataEncryptionCipher.AesGcm
}, cancellationToken);
#pragma warning restore CS0618 // Type or member is obsolete
Console.WriteLine($"Encrypted bytes: '{Convert.ToBase64String(encryptedBytesResult)}'");
Console.WriteLine($"Encrypted bytes: '{Convert.ToBase64String(encryptedBytesResult.Span)}'");
Console.WriteLine();

//Decrypt the temp file from a memory stream this time instead of a file
await using var ms = new MemoryStream(encryptedBytesResult);
await using var ms = new MemoryStream(encryptedBytesResult.ToArray());
#pragma warning disable CS0618 // Type or member is obsolete
var decryptedBytes = await client.DecryptAsync(componentName, ms, keyName, cancellationToken);
var decryptedBytes = await client.DecryptAsync(componentName, ms, keyName, new DecryptionOptions(), cancellationToken);
#pragma warning restore CS0618 // Type or member is obsolete

Console.WriteLine("Decrypted value:");
await using var decryptedMs = new MemoryStream(decryptedBytes);
await using var decryptedMs = new MemoryStream(decryptedBytes.ToArray());
using var sr = new StreamReader(decryptedMs);
Console.WriteLine(await sr.ReadToEndAsync(cancellationToken));

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / run integration tests (6.0)

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / run integration tests (6.0)

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / Build

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / Build

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / run integration tests (7.0)

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / run integration tests (7.0)

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / Test .NET 6.0

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / run integration tests (8.0)

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / run integration tests (8.0)

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / Test .NET 7.0

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / Test .NET 7.0

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / Test .NET 8.0

No overload for method 'ReadToEndAsync' takes 1 arguments

Check failure on line 58 in examples/Client/Cryptography/Examples/EncryptDecryptFileStreamExample.cs

View workflow job for this annotation

GitHub Actions / Test .NET 8.0

No overload for method 'ReadToEndAsync' takes 1 arguments
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public override async Task RunAsync(CancellationToken cancellationToken)
//Encrypt the string
var plaintextBytes = Encoding.UTF8.GetBytes(plaintextStr);
#pragma warning disable CS0618 // Type or member is obsolete
var encryptedBytesResult = await client.EncryptAsync(componentName, plaintextBytes, KeyWrapAlgorithm.Rsa, keyName, DataEncryptionCipher.AesGcm,
var encryptedBytesResult = await client.EncryptAsync(componentName, plaintextBytes, keyName, new EncryptionOptions(KeyWrapAlgorithm.Rsa),
cancellationToken);
#pragma warning restore CS0618 // Type or member is obsolete

Console.WriteLine($"Encrypted bytes: '{Convert.ToBase64String(encryptedBytesResult)}'");
Console.WriteLine($"Encrypted bytes: '{Convert.ToBase64String(encryptedBytesResult.Span)}'");

//Decrypt the string
#pragma warning disable CS0618 // Type or member is obsolete
var decryptedBytes = await client.DecryptAsync(componentName, encryptedBytesResult, keyName, cancellationToken);
var decryptedBytes = await client.DecryptAsync(componentName, encryptedBytesResult, keyName, new DecryptionOptions(), cancellationToken);
#pragma warning restore CS0618 // Type or member is obsolete
Console.WriteLine($"Decrypted string: '{Encoding.UTF8.GetString(decryptedBytes)}'");
Console.WriteLine($"Decrypted string: '{Encoding.UTF8.GetString(decryptedBytes.ToArray())}'");
}
}
}

0 comments on commit 6fc560d

Please sign in to comment.