Coder Social home page Coder Social logo

mysto / python-fpe Goto Github PK

View Code? Open in Web Editor NEW
89.0 89.0 18.0 144 KB

FPE - Format Preserving Encryption with FF3 in Python

Home Page: https://privacylogistics.com

License: Apache License 2.0

Python 100.00%
anonymization crypto cryptographic cryptography encryption ff3 format-preserving-encryption fpe nist-recommendation nist-specification privacy-enhancing-technologies privacy-tools python tokenization

python-fpe's People

Contributors

bschoening avatar jrobichaud avatar maresb avatar puspendubanerjee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-fpe's Issues

Missing setup.py

The setup.py file which appears on PyPI does not appear in this repository.

You may want to set up a CI workflow which publishes tagged commits to PyPI automatically, and for that you'd need to include the setup.py.

plaintext string is not within base/radix {self.radix}

Running the example code from the README with

plaintext = "0000000000000000"

produces the error

ValueError: plaintext string is not within base/radix {self.radix}

The relevant part of the Python code is

        # Check if the plaintext message is formatted in the current radix
        x = int(plaintext, self.radix)
        if x == 0:
            raise ValueError("plaintext string is not within base/radix {self.radix}")

I don't follow the logic here since if there is a problem with the string not conforming to the base, the int() function should raise a ValueError, for example

>>> int("a", 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 2: 'a'

Thus it seems to me like the check for x == 0 should be removed.

Using the use of logging.debug() in FF3 breaks our structured logging system

We are currently using structlog in our application and I noticed a weird bug when using the FF3 package.

As soon as FF3 gets used in our code our structured logging breaks. This seems to be due to the use of logging.debug() in the FF3 package. We believe that its because logging.debug() uses the root logger.

Here an example of the use of this function in the FF3 code:
logging.debug(f"Tweak: {tweak}, tweakBytes:{tweakBytes.hex()}")

We suggest switching it to using a named logger like this:

logger = logging.getLogger(__name__) 
logger.debug(f"Tweak: {tweak}, tweakBytes:{tweakBytes.hex()}")

Ff3-1 aes256 key and tweak Generation

Thanks for this! I'm using your library atm to protect some testing data and it works great. But how can I generate an ff3-1 key and tweak for usage with aes256 block cipher please?

Leading / trailing zeros causes `ValueError` during .encrypt

When I do the following:

c = FF3Cipher(key, tweak, radix=36)
my_str = '100000'
fpe = c.encrypt(my_str)

I get this error:
ValueError: string 000 is not within base/radix

The same error will occur with my_str = '000001' but does not occur with my_str = '100001'. Is this expected? I don't see anything in the specification about a limitation on leading / trailing zeros.

module 'Crypto.Cipher.AES' has no attribute 'AESCipher'

Hi There,

I'm running this on Python 3.9.2 and I'm getting the package ff-3.py

\lib\site-packages\ff3\ff3.py", line 90, in init self.aesBlock = AES.AESCipher(reverse_string(self.key))

Code from ff-3.py line 90

aes.NewCipher automatically returns the correct block based on the length of the key

    # Always use the reversed key since Encrypt and Decrypt call ciph expecting that

    self.aesBlock = AES.AESCipher(reverse_string(self.key))

I've imported the package crypto. cipher but I couldn't find the AESCipher but it seems to be under crypto, let me know what do you think?

Not an issue, actually

I just wanted to let you know that I have used some of your test vectors to verify my C-implementation of the FPE algorithms. Of course I have mentioned the source and credit. Please feel free to check out the testvectors folder of this repository and inform me of any issues.

Cheers

Want to make sure this algorithm will not generate collisions

Hello, I'm using this module to convert the id of a order to a 12-digit confirmation number, for example:

Order ID 1 = 000000000001 --> 457845269874
Order ID 2 = 000000000002 --> 784378928745

My code goes like this:

key = 'C4D91A3F7B61834E90FD72563CACF01E'
tweak = 'ABD39280979565'
c = FF3Cipher(key, tweak)

order_id = 1
order_id_padded = f'{order_id:012}'
confirmation_number = c.encrypt(order_id_padded)

I assume that as long as I don't change the key or the tweak I should not have any collision issues of two order ids generating the same confirmation number. Is this correct?

Thanks for your time

FF1

I started using the FF3-1 implementation recently and its super cool. However I was approached if FF1 would also be an option.
I was told its "better" as in "more secure" than FF3-1.

I dont know if that is true, but I certainly know that I can not implement FF1 in Python now.

Would it be something to consider to also add FF1 support please?

Include broad .gitignore

Having a broad range of environment-specific stuff is good in my experience. That allows contributors to use whatever tools they want without going through the mess we saw with the .idea/ files. If the Python package is set up properly, the .gitignore won't be included in the PyPI distribution.

In the end, it won't prevent you from git adding files. It just prevents git from suggesting irrelevant files to add.

I read over @PuspenduBanerjee's .gitignore and it looks perfectly good to me. I'd recommend restoring it. Or at the very least find a standard Python-oriented .gitignore from somewhere.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.