https://github.com/alexey-lapin/eme-java
EME (Encrypt-Mix-Encrypt) wide-block encryption for Java.
https://github.com/alexey-lapin/eme-java
cipher ecryption wide-block-encryption
Last synced: 3 months ago
JSON representation
EME (Encrypt-Mix-Encrypt) wide-block encryption for Java.
- Host: GitHub
- URL: https://github.com/alexey-lapin/eme-java
- Owner: alexey-lapin
- License: mit
- Created: 2021-07-22T19:36:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2026-01-16T12:51:03.000Z (3 months ago)
- Last Synced: 2026-01-17T03:33:31.959Z (3 months ago)
- Topics: cipher, ecryption, wide-block-encryption
- Language: Java
- Homepage:
- Size: 251 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
EME for Java [](https://central.sonatype.com/artifact/com.github.alexey-lapin.eme-cipher/eme-cipher) [](https://codecov.io/gh/alexey-lapin/eme-java)
==========
This is a port of [EME for Go](https://github.com/rfjakob/eme).
**EME** (ECB-Mix-ECB or, clearer, **Encrypt-Mix-Encrypt**) is a wide-block
encryption mode developed by Halevi
and Rogaway in 2003.
EME uses multiple invocations of a block cipher to construct a new
cipher of bigger block size (in multiples of 16 bytes, up to 2048 bytes).
Quoting from the original paper:
> We describe a block-cipher mode of operation, EME, that turns an n-bit block cipher into
> a tweakable enciphering scheme that acts on strings of mn bits, where m ∈ [1..n]. The mode is
> parallelizable, but as serial-efficient as the non-parallelizable mode CMC [6]. EME can be used
> to solve the disk-sector encryption problem. The algorithm entails two layers of ECB encryption
> and a “lightweight mixing” in between. We prove EME secure, in the reduction-based sense of
> modern cryptography.
This is an implementation of EME in Java, complete with test vectors from IEEE and Halevi.
It has no dependencies outside the standard library.
## Usage
Maven:
```xml
com.github.alexey-lapin.eme-cipher
eme-cipher
0.2.0
```
Gradle:
```
implementation("com.github.alexey-lapin.eme-cipher:eme-cipher:0.2.0")
```
### As a javax.crypto.Cipher
```java
import com.github.alexeylapin.eme.cipher.AES128EMEProvider;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.Security;
public class Example {
public static void main(String[] args) throws Exception {
// register eme provider
Security.addProvider(new AES128EMEProvider());
// create cipher
Cipher cipher = Cipher.getInstance("AES/EME/PKCS7Padding");
// initialize cipher
byte[] key = new byte[32];
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
byte[] iv = new byte[16];
cipher.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(iv));
// use cipher
byte[] data = new byte[100];
byte[] encrypted = cipher.update(data);
}
}
```
### As a custom impl
```java
import com.github.alexeylapin.eme.EME;
public class Example {
public static void main(String[] args) throws Exception {
// initialize cipher
byte[] key = new byte[32];
EME eme = EME.fromKey(key);
byte[] iv = new byte[16];
// use cipher
byte[] data = new byte[512];
byte[] encrypted = eme.encrypt(iv, data);
}
}
```