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

serialization not works! #1

Open
membrown opened this issue Jun 6, 2015 · 2 comments
Open

serialization not works! #1

membrown opened this issue Jun 6, 2015 · 2 comments
Assignees

Comments

@membrown
Copy link

membrown commented Jun 6, 2015

hello

I use this code for generating and then serializing the AES white box instance

System.out.println("generate");
Generator gEnc = new Generator();
Generator gDec = new Generator();
Random rand = new Random();

// External encoding is needed, at least some, generate identities
ExternalBijections extc = new ExternalBijections();
gEnc.generateExtEncoding(extc, 0);

// at first generate pure table AES implementation
gEnc.setUseIO04x04Identity(false);
gEnc.setUseIO08x08Identity(false);
gEnc.setUseMB08x08Identity(false);
gEnc.setUseMB32x32Identity(false);

gDec.setUseIO04x04Identity(false);
gDec.setUseIO08x08Identity(false);
gDec.setUseMB08x08Identity(false);
gDec.setUseMB32x32Identity(false);

// Generate AES for encryption
gEnc.generate(true, AEShelper.testVect128_key, 16, extc);
AES AESenc = gEnc.getAESi();

// Generate AES for decryption
gDec.generate(false, AEShelper.testVect128_key, 16, extc);
AES AESdec = gDec.getAESi();


//********************************
try {

    FileOutputStream fileOut
            = new FileOutputStream("AESenc.ser");
    ObjectOutputStream out = new ObjectOutputStream(fileOut);
    out.writeObject(AESenc);
    out.close();
    fileOut.close();
    System.out.printf("Serialized data is saved in AESenc.ser");
} catch (IOException i) {
    i.printStackTrace();
}

try {
    FileOutputStream fileOut
            = new FileOutputStream("AESdec.ser");
    ObjectOutputStream out = new ObjectOutputStream(fileOut);
    out.writeObject(AESdec);
    out.close();
    fileOut.close();
    System.out.printf("Serialized data is saved in AESdec.ser");
} catch (IOException i) {
    i.printStackTrace();
}

but when read file and de-serialize objects encrypt/decrypt not work properly
this is code

Generator gEnc = new Generator();
Generator gDec = new Generator();
Random rand = new Random();

// External encoding is needed, at least some, generate identities
ExternalBijections extc = new ExternalBijections();
gEnc.generateExtEncoding(extc, 0);

// at first generate pure table AES implementation
gEnc.setUseIO04x04Identity(false);
gEnc.setUseIO08x08Identity(false);
gEnc.setUseMB08x08Identity(false);
gEnc.setUseMB32x32Identity(false);

gDec.setUseIO04x04Identity(false);
gDec.setUseIO08x08Identity(false);
gDec.setUseMB08x08Identity(false);
gDec.setUseMB32x32Identity(false);

AES AESenc ;
AES AESdec ;

try {
    FileInputStream fileIn = new FileInputStream("AESenc.ser");
    ObjectInputStream in = new ObjectInputStream(fileIn);
    AESenc = (AES) in.readObject();
    in.close();
    fileIn.close();
} catch (IOException i) {
    i.printStackTrace();
    return;
} catch (ClassNotFoundException c) {
    System.out.println("AESenc.ser not found");
    c.printStackTrace();
    return;
}

try {
    FileInputStream fileIn = new FileInputStream("AESdec.ser");
    ObjectInputStream in = new ObjectInputStream(fileIn);
    AESdec = (AES) in.readObject();
    in.close();
    fileIn.close();
} catch (IOException i) {
    i.printStackTrace();
    return;
} catch (ClassNotFoundException c) {
    System.out.println("AESenc.ser not found");
    c.printStackTrace();
    return;
}

//################################
gEnc.setAESi(AESenc);
gDec.setAESi(AESdec);

.
.
.
// Encrypt
state.transpose();
gEnc.applyExternalEnc(state, extc, true);
AESenc.crypt(state);
gEnc.applyExternalEnc(state, extc, false);

    System.out.println("Enc(plaintext_test): \n" + state);
    //assertEquals("Cipher output mismatch", true, state.equals(cipher));

    // Decrypt
    state.transpose();
    System.out.println("T(Enc(plaintext_test)): \n" + state);
    gDec.applyExternalEnc(state, extc, true);
    AESdec.crypt(state);
    gDec.applyExternalEnc(state, extc, false);
    System.out.println("Dec(T(Enc(plaintext_test))): \n" + state.toString());
    System.out.println(new String(state.getStateCopy()));

but not work
please help me.

@AmrAshraf
Copy link

@membrown Could you share with us what is the status of your issue and if you solve the issue?

@iprovalo
Copy link

iprovalo commented Jul 24, 2023

@membrown @AmrAshraf you can try it with this PR.

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

No branches or pull requests

4 participants