Giter Site home page Giter Site logo

rusakovichma / ecb-encryption-research Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 247 KB

Simple demonstration of ECB encryption problem

Home Page: https://mikhailrusakovich.wordpress.com/2019/11/29/java-cipher-usage-aspects/

Java 100.00%
aes-ecb aes-ecb-mode ecb-encryption ecb-mode encryption-attack java unit-tests attack-prevention

ecb-encryption-research's Introduction

Attacks on AES-ECB encryption

ECB encrypts identical plaintext blocks into identical ciphertext blocks, it does not hide data patterns well. In some senses, it doesn't provide serious message confidentiality, and it is not recommended for use in cryptographic protocols at all.

A striking example of the degree to which ECB can leave plaintext data patterns in the ciphertext can be seen when ECB mode is used to encrypt a bitmap image which uses large areas of uniform color. While the color of each individual pixel is encrypted, the overall image may still be discerned, as the pattern of identically colored pixels in the original remains in the encrypted version.

ECB mode can also make protocols without integrity protection even more susceptible to replay attacks, since each block gets decrypted in exactly the same way.

Here's an image of an unencrypted secret:
Unencrypted secret image

After ECB encryption:
ECB encryption secret image

Code example

Full example may be found here: https://github.com/rusakovichma/ecb-encryption-research/blob/master/src/test/java/com/github/rusakovichma/encryption/ecb/research/service/TripleDesEncryptionServiceTest.java

    @Test
    void ecbEncryptionTest() {
        //Encryption provider initialize
        EncryptionKeyProvider keyProvider = new TripleDesEncryptionKeyProvider();
        EncryptionService encryptionService = new TripleDesEncryptionService(keyProvider);

        //read the image
        PlainFileEntity secretImage = FileUtil.read(RESOURCES_FOLDER + "secret1.bmp");
        //encrypt the image
        byte[] encryptedImage = encryptionService.encrypt(secretImage.getContent());
        //set image content
        secretImage.setContent(encryptedImage);

        //Encrypted Image for Analysis
        final String encryptedSecretPath = RESOURCES_FOLDER + "secret1_encrypted.bmp";
        //save encrypted image
        FileUtil.save(secretImage, encryptedSecretPath);
        assertImageExists(true, encryptedSecretPath);
    }

ecb-encryption-research's People

Contributors

rusakovichma avatar

Watchers

 avatar  avatar

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.