Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would you please support the binary secret key? #13

Closed
jemygraw opened this issue Oct 19, 2023 · 2 comments · Fixed by #14
Closed

Would you please support the binary secret key? #13

jemygraw opened this issue Oct 19, 2023 · 2 comments · Fixed by #14
Labels
enhancement New feature or request

Comments

@jemygraw
Copy link

jemygraw commented Oct 19, 2023

Currently the secret key must be a utf-8 encoded string but in some cases we have to use the binary secret key.
Thx if possible. For the current workaround solution, I implements my own class for anybody who may need it.

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.ciphers.modes import ECB

from aes_pkcs5.algorithms import AESCommon, Cipher, OUTPUT_FORMATS


class AESECBPKCS5Padding(AESCommon):
    """
    Implements AES algorithm with ECB mode of operation and padding scheme PKCS5.
    """

    def __init__(self, key: bytes, output_format: str):
        super().__init__('0', output_format)
        self._key = key

        if output_format not in OUTPUT_FORMATS:
            raise NotImplementedError(
                f"Support for output format: {output_format} is not implemented"
            )

        self._output_format = output_format

    def _get_cipher(self):
        """Return AES/CBC/PKCS5Padding Cipher"""
        return Cipher(AES(self._key), mode=ECB(), backend=default_backend())
@Laerte
Copy link
Owner

Laerte commented Dec 13, 2023

Hello @jemygraw I will take a look and implement this feature in the next version, thanks!

@Laerte
Copy link
Owner

Laerte commented Dec 13, 2023

Implemented on 1.0.3 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants