maythamfahmi / CryptoNet

CryptoNet is simple, fast and a lightweight asymmetric and symmetric encryption library.
https://github.com/maythamfahmi/CryptoNet
MIT License
101 stars 19 forks source link

[Bug]: CryptoNetAes.ExportKey takes bool? set to null, and never uses it. #101

Closed jwdonahue closed 1 month ago

jwdonahue commented 1 month ago

Contact Details

No response

What happened?

Naming vs function aside, why default a bool to null, and never use it?

Version

2.4.x >= (Default)

What Operating System are you seeing the problem on?

No response

Relevant log output

public string ExportKey(bool? privateKey = null)
    {
        return CryptoNetUtils.ExportAndSaveAesKey(Aes);
    }

Code of Conduct

maythamfahmi commented 1 month ago

one way of sloving this is by introducing to interfaces one fo RSA and one for AES, some thing like

public interface ICryptoNetAes : ICryptoNet
{
    string ExportKey();
    void ExportKeyAndSave(FileInfo fileInfo);
}

and

public interface ICryptoNetRsa : ICryptoNet
{
    string ExportKey(bool privateKey = false);
    void ExportKeyAndSave(FileInfo fileInfo, bool privateKey = false);
}

I am going this way, is there otehr options?

jwdonahue commented 1 month ago

Something like this maybe?

public record Key : IGetKey, ISaveKey
{
    string Getkey();
    void SaveKey(string filename);
    void SaveKey(FileInfo fileInfo);
}
public interface ICryptoNetAes : ICryptoNet
{
    Key GetKey();
}
public interface ICryptoNetRsa : ICryptoNet
{
    Key GetPrivateKey()
    Key GetPublicKey()
}

I need to sleep on it.

maythamfahmi commented 1 month ago

Have a nice evening and sleep well

jwdonahue commented 1 month ago

Maybe a hierarchy of Key types, derived from Key, with a handful of static factory methods for each of the specialized types?

maythamfahmi commented 1 month ago

101 will also sovle #102.

maythamfahmi commented 1 month ago

I like your suggestion https://github.com/maythamfahmi/CryptoNet/issues/101#issuecomment-2421884593, but at this stage I just chosen to keep it on this suggestion https://github.com/maythamfahmi/CryptoNet/issues/101#issuecomment-2421773796. If we think at later point it need more attention, we could perhaps revisit your suggestion.

maythamfahmi commented 1 month ago

PR https://github.com/maythamfahmi/CryptoNet/pull/106