Skip to content

Commit

Permalink
Feature/release2.2.0 (#35)
Browse files Browse the repository at this point in the history
* #28 class renamed

* remove todo

* update nugets

Co-authored-by: Maytham Fahmi <maythamfahmi@nextbix.dk>
Co-authored-by: Maytham Fahmi <mfa@kwbruun.dk>
  • Loading branch information
3 people authored Oct 28, 2022
1 parent 797decd commit 453fe80
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
13 changes: 8 additions & 5 deletions CryptoNet.UnitTests/CryptoNet.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Shouldly" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions CryptoNet/CryptoNetAes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public CryptoNetAes()
Aes.GenerateKey();
Aes.GenerateIV();
Info = CreateDetails(Aes.Key, Aes.IV);
Aes.Key = Info.AesDetail!.KeyInfo.Key;
Aes.IV = Info.AesDetail!.KeyInfo.Iv;
Aes.Key = Info.AesDetail!.AesKeyValue.Key;
Aes.IV = Info.AesDetail!.AesKeyValue.Iv;
}

public CryptoNetAes(string key)
Expand All @@ -35,8 +35,8 @@ public CryptoNetAes(string key)
Aes.KeySize = 256;
var keyInfo = CryptoNetUtils.ImportAesKey(key);
Info = CreateDetails(keyInfo.Key, keyInfo.Iv);
Aes.Key = Info.AesDetail!.KeyInfo.Key;
Aes.IV = Info.AesDetail!.KeyInfo.Iv;
Aes.Key = Info.AesDetail!.AesKeyValue.Key;
Aes.IV = Info.AesDetail!.AesKeyValue.Iv;
}

public CryptoNetAes(FileInfo fileInfo)
Expand All @@ -45,17 +45,17 @@ public CryptoNetAes(FileInfo fileInfo)
Aes.KeySize = 256;
var keyInfo = CryptoNetUtils.ImportAesKey(CryptoNetUtils.LoadFileToString(fileInfo.FullName));
Info = CreateDetails(keyInfo.Key, keyInfo.Iv);
Aes.Key = Info.AesDetail!.KeyInfo.Key;
Aes.IV = Info.AesDetail!.KeyInfo.Iv;
Aes.Key = Info.AesDetail!.AesKeyValue.Key;
Aes.IV = Info.AesDetail!.AesKeyValue.Iv;
}

public CryptoNetAes(byte[] key, byte[] iv)
{
Aes = Aes.Create();
Aes.KeySize = 256;
Info = CreateDetails(key, iv);
Aes.Key = Info.AesDetail!.KeyInfo.Key;
Aes.IV = Info.AesDetail!.KeyInfo.Iv;
Aes.Key = Info.AesDetail!.AesKeyValue.Key;
Aes.IV = Info.AesDetail!.AesKeyValue.Iv;
}

private CryptoNetInfo CreateDetails(byte[] key, byte[] iv)
Expand Down
6 changes: 3 additions & 3 deletions CryptoNet/Models/CryptoNetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public AesDetail(byte[] key, byte[] iv)
throw new ArgumentNullException(nameof(iv));
}

KeyInfo = new KeyInfo()
AesKeyValue = new AesKeyValue()
{
Key = key,
Iv = iv
};
}

public Aes? Aes { get; set; }
public KeyInfo KeyInfo { get; set; }
public AesKeyValue AesKeyValue { get; set; }
}

[Serializable()]
public class KeyInfo
public class AesKeyValue
{
[System.Xml.Serialization.XmlElement("key")]
public byte[] Key { get; set; }
Expand Down
12 changes: 6 additions & 6 deletions CryptoNet/Utils/CryptoNetUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ internal static void SaveKey(string filename, string content)

internal static string ExportAndSaveAesKey(Aes aes)
{
KeyInfo keyInfo = new KeyInfo { Key = aes.Key, Iv = aes.IV };
XmlSerializer serializer = new XmlSerializer(typeof(KeyInfo));
AesKeyValue aesKeyValue = new AesKeyValue { Key = aes.Key, Iv = aes.IV };
XmlSerializer serializer = new XmlSerializer(typeof(AesKeyValue));
StringWriter writer = new StringWriter();
serializer.Serialize(writer, keyInfo);
serializer.Serialize(writer, aesKeyValue);
writer.Close();
return writer.ToString();
}

internal static KeyInfo ImportAesKey(string aes)
internal static AesKeyValue ImportAesKey(string aes)
{
XmlSerializer deserializer = new XmlSerializer(typeof(KeyInfo));
XmlSerializer deserializer = new XmlSerializer(typeof(AesKeyValue));
StringReader reader = new StringReader(aes);
return (KeyInfo)deserializer.Deserialize(reader)!;
return (AesKeyValue)deserializer.Deserialize(reader)!;
}

internal static string GetDescription(KeyType value)
Expand Down

0 comments on commit 453fe80

Please sign in to comment.