Comments (5)
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.
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.
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.
I am also facing the same issue, any updates on this?
from format-preserving-encryption-java.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from format-preserving-encryption-java.