public class StreamingGCMAESPacketMode extends java.lang.Object implements StreamingEncryptionScheme
StreamingGCMAES is that the plain text is
split up in packets of a well defined size and each of these packets is
encrypted with their own IV rather than encrypting the plaintext at once.
This reduces the memory overhead that the GCM implementation has. Each plain
text is always stored internally while decrypting because the validation of
the GCM tag can only be performed when the whole cipher text is decrypted and
no unauthorizated data should be provided beforehand.
Another problem that the StreamingGCMAES implementation has, is that
it is not a streaming scheme. You can't write the cipher text in the one
stream and read the decrypted ciphertext in the other stream since the
decrypted ciphertext will be written when you finished writing your cipher
text (and close the stream).
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_KEY_SIZE |
static int |
DEFAULT_PACKET_SIZE |
| Constructor and Description |
|---|
StreamingGCMAESPacketMode() |
StreamingGCMAESPacketMode(int packetSize) |
StreamingGCMAESPacketMode(int packetSize,
int symmetricKeyLength) |
StreamingGCMAESPacketMode(org.cryptimeleon.math.serialization.Representation repr) |
| Modifier and Type | Method and Description |
|---|---|
java.io.OutputStream |
createDecryptor(java.io.OutputStream out,
DecryptionKey privateKey)
Returns an OutputStream that decrypts any bytes written to it
and writes the resulting plaintext to out.
|
java.io.OutputStream |
createEncryptor(java.io.OutputStream out,
EncryptionKey publicKey)
Returns an OutputStream that encrypts any bytes written to it
and writes the resulting ciphertext to out.
|
PlainText |
decrypt(CipherText cipherText,
DecryptionKey privateKey)
Decrypts the given cipher text using the given decryption key.
|
java.io.InputStream |
decrypt(java.io.InputStream in,
DecryptionKey privateKey)
Returns an InputStream containing the plaintext obtained
by decrypting the content of in.
|
java.io.InputStream |
encrypt(java.io.InputStream in,
EncryptionKey publicKey)
Returns an InputStream containing the ciphertext obtained
by encrypting the content of in.
|
CipherText |
encrypt(PlainText plainText,
EncryptionKey publicKey)
Encrypts the given plain text using the given encryption key.
|
boolean |
equals(java.lang.Object obj) |
SymmetricKey |
generateSymmetricKey()
Generates a symmetric key, which is a random key with a specified length.
|
org.cryptimeleon.math.serialization.Representation |
getRepresentation() |
int |
hashCode() |
CipherText |
restoreCipherText(org.cryptimeleon.math.serialization.Representation repr)
Restores the ciphertext corresponding to the given representation.
|
DecryptionKey |
restoreDecryptionKey(org.cryptimeleon.math.serialization.Representation repr)
Restores the decryption key corresponding to the given representation.
|
EncryptionKey |
restoreEncryptionKey(org.cryptimeleon.math.serialization.Representation repr)
Restores the encryption key corresponding to the given representation.
|
PlainText |
restorePlainText(org.cryptimeleon.math.serialization.Representation repr)
Restores the plaintext corresponding to the given representation.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitdecrypt, encryptdecrypt, encrypt, restoreFromRepresentationpublic static final int DEFAULT_PACKET_SIZE
public static final int DEFAULT_KEY_SIZE
public StreamingGCMAESPacketMode(org.cryptimeleon.math.serialization.Representation repr)
public StreamingGCMAESPacketMode(int packetSize,
int symmetricKeyLength)
public StreamingGCMAESPacketMode(int packetSize)
public StreamingGCMAESPacketMode()
public CipherText encrypt(PlainText plainText, EncryptionKey publicKey)
EncryptionSchemeencrypt in interface EncryptionSchemeplainText - the plaintext to encryptpublicKey - the key to use for encryptionpublic PlainText decrypt(CipherText cipherText, DecryptionKey privateKey)
EncryptionSchemedecrypt in interface EncryptionSchemecipherText - the ciphertext to decryptprivateKey - the key to use for decryptionpublic PlainText restorePlainText(org.cryptimeleon.math.serialization.Representation repr)
EncryptionSchemerestorePlainText in interface EncryptionSchemerepr - the representation to restore the plaintext frompublic CipherText restoreCipherText(org.cryptimeleon.math.serialization.Representation repr)
EncryptionSchemerestoreCipherText in interface EncryptionSchemerepr - the representation to restore the ciphertext frompublic EncryptionKey restoreEncryptionKey(org.cryptimeleon.math.serialization.Representation repr)
EncryptionSchemerestoreEncryptionKey in interface EncryptionSchemerepr - the representation to restore the encryption key frompublic DecryptionKey restoreDecryptionKey(org.cryptimeleon.math.serialization.Representation repr)
EncryptionSchemerestoreDecryptionKey in interface EncryptionSchemerepr - the representation to restore the decryption key frompublic org.cryptimeleon.math.serialization.Representation getRepresentation()
getRepresentation in interface org.cryptimeleon.math.serialization.Representablepublic java.io.InputStream encrypt(java.io.InputStream in,
EncryptionKey publicKey)
throws java.io.IOException
Note that calling this may already cause some bytes to be read from in.
Returns an InputStream that encrypts the bytes read from the
given InputStream in. The stream will always read enough
bytes from the underlying stream to encrypt a new packet, buffer it and
return bytes from it when read is being called. This stream is optimized
for the use of InputStream.read(byte[]) and
InputStream.read(byte[], int, int).
encrypt in interface StreamingEncryptionSchemein - stream containing the bytes to encryptpublicKey - the key to encrypt withjava.io.IOExceptionpublic java.io.OutputStream createEncryptor(java.io.OutputStream out,
EncryptionKey publicKey)
throws java.io.IOException
Note that calling this may already cause some bytes to be written to out.
Returns an OutputStream that encrypts any bytes that are written
into it and write the encrypted bytes into the
OutputStream out. The stream will always try to buffer
enough bytes to encrypt a packet and write it into
theOutputStream out.
This stream is optimized for the use of
OutputStream.write(byte[]) and
OutputStream.write(byte[], int, int).
OutputStream.flush() will encrypt the currently buffered data as
a packet.
createEncryptor in interface StreamingEncryptionSchemeout - the stream to write the ciphertext to.publicKey - the key to encrypt with.java.io.IOExceptionpublic java.io.InputStream decrypt(java.io.InputStream in,
DecryptionKey privateKey)
throws java.io.IOException
Note that calling this may already cause some bytes to be read from in.
Returns an InputStream that decrypts the encrypted bytes of the
InputStream InputStream in. The InpuStream will buffer a
packet and decrypt it and then read the bytes out of this packet. This
stream is optimized, so the use of InputStream.read(byte[]) and
InputStream.read(byte[], int, int) is advised.
decrypt in interface StreamingEncryptionSchemein - in stream containing the bytes to decryptprivateKey - the key to decrypt with.java.io.IOExceptionpublic java.io.OutputStream createDecryptor(java.io.OutputStream out,
DecryptionKey privateKey)
throws java.io.IOException
Note that calling this may already cause some bytes to be written to out.
Returns an OutputStream that decrypts any bytes that are written
into it and write the decrypted bytes into the
OutputStream out. The stream will always try to buffer
enough bytes to decrypt a packet and write the decrypted packet into
theOutputStream out.
This stream is optimized for the use of
OutputStream.write(byte[]) and
OutputStream.write(byte[], int, int).
OutputStream.flush() will decrypt the currently buffered data as
a packet.
createDecryptor in interface StreamingEncryptionSchemeout - the stream to write the plaintext to.privateKey - the key to decrypt with.java.io.IOExceptionpublic SymmetricKey generateSymmetricKey()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Object