GithubHelp home page GithubHelp logo

Comments (5)

lijhua avatar lijhua commented on August 16, 2024 2

I also encountered this problem in the beginning, and solved it in the following way.
1, if the content to be encrypted contains only numbers, then construct NUM_CHARS like this
private static final char[] NUM_CHARS = new char[] {'1', '2', '3', '4', '5', '6', '7', '8', '9' , '0'};
2, if the content to be encrypted contains numbers and uppercase letters, then construct NUM_CHARS
private static final char[] NUM_CHARS = new char[] {'1', '2', '3', '4', '5', '6', '7', '8','9','0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
3, other situations are changed with steps 1 and 2

then

BasicNums numAlphabet=new BasicNums();
TextToIntTransformer textToIntTransformer = new GenericTransformations(numAlphabet.availableCharacters());
IntToTextTransformer intToTextTransformer = new GenericTransformations(numAlphabet.availableCharacters());
String secretKey = "privateKeyText";
// with default values
FormatPreservingEncryption formatPreservingEncryption = FormatPreservingEncryptionBuilder
.ff1Implementation()
.withDomain(new GenericDomain(new BasicNums(), textToIntTransformer, intToTextTransformer))
.withDefaultPseudoRandomFunction(secretKey.getBytes())
.withDefaultLengthRange()
.build();

    String cipherText = formatPreservingEncryption.encrypt("1212321ASDSAD", "2088".getBytes());
    System.out.println(cipherText);
    String plainText = formatPreservingEncryption.decrypt(cipherText, "2088".getBytes());
    System.out.println(plainText);

output:
WU69RQ3AB5IRR
1212321ASDSAD

from format-preserving-encryption-java.

laki88 avatar laki88 commented on August 16, 2024 1

To solve that, I have created below class and added to classpath

package com.wso2telco.dep.user.masking;

import com.idealista.fpe.config.Alphabet;

public class BasicNums implements Alphabet {

    private static final char[] NUM_CHARS = new char[] {'1', '2', '3', '4', '5', '6', '7', '8', '9' , '0'};

    @Override
    public char[] availableCharacters() {
        return NUM_CHARS ;
    }

    @Override
    public Integer radix() {
        return NUM_CHARS.length;
    }
}

and used it as in below code

BasicNums numAlphabet = new BasicNums();
        TextToIntTransformer textToIntTransformer = new GenericTransformations(numAlphabet.availableCharacters());
        IntToTextTransformer intToTextTransformer = new GenericTransformations(numAlphabet.availableCharacters());

        // with default values
        FormatPreservingEncryption formatPreservingEncryption = FormatPreservingEncryptionBuilder
                .ff1Implementation()
                .withDomain(new GenericDomain(new BasicNums(), textToIntTransformer, intToTextTransformer))
                .withDefaultPseudoRandomFunction(secretKey.getBytes())
                .withDefaultLengthRange()
                .build();

from format-preserving-encryption-java.

laki88 avatar laki88 commented on August 16, 2024

The problem is it can't encrypt a number sequence. when I use letters in alphabet for the input stream I can encrypt and decrypt it without any issue.

from format-preserving-encryption-java.

meghnad-globalids avatar meghnad-globalids commented on August 16, 2024

I am also facing the same issue, any updates on this?

from format-preserving-encryption-java.

meghnad-globalids avatar meghnad-globalids commented on August 16, 2024

Will be possible for this encryption tool to encrypt character wise based on domain, as in my case the
string might be alphanumeric?

from format-preserving-encryption-java.

Related Issues (8)

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.