Skip to content

Commit d268460

Browse files
committed
AEAD (AES) refactoring
1 parent 783abd6 commit d268460

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

crypto-tink/src/main/java/de/dominikschadow/javasecurity/tink/symmetric/AeadDemo.java renamed to crypto-tink/src/main/java/de/dominikschadow/javasecurity/tink/aead/AesEaxWithGeneratedKey.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package de.dominikschadow.javasecurity.tink.symmetric;
18+
package de.dominikschadow.javasecurity.tink.aead;
1919

2020
import com.google.crypto.tink.Aead;
2121
import com.google.crypto.tink.KeysetHandle;
@@ -30,19 +30,19 @@
3030

3131
/**
3232
* Shows crypto usage with Google Tink for the Authenticated Encryption with Associated Data (AEAD) primitive. The used
33-
* key is generated during runtime and not saved.
33+
* key is generated during runtime and not saved. Selected algorithm is AES-EAX with 256 bit.
3434
*
3535
* @author Dominik Schadow
3636
*/
37-
public class AeadDemo {
38-
private static final Logger log = LoggerFactory.getLogger(AeadDemo.class);
37+
public class AesEaxWithGeneratedKey {
38+
private static final Logger log = LoggerFactory.getLogger(AesEaxWithGeneratedKey.class);
3939
private static final String INITIAL_TEXT = "Some dummy text to work with";
4040
private static final String ASSOCIATED_DATA = "Some additional data";
4141

4242
/**
4343
* Init AeadConfig in the Tink library.
4444
*/
45-
private AeadDemo() {
45+
private AesEaxWithGeneratedKey() {
4646
try {
4747
AeadConfig.register();
4848
} catch (GeneralSecurityException ex) {
@@ -51,7 +51,7 @@ private AeadDemo() {
5151
}
5252

5353
public static void main(String[] args) {
54-
AeadDemo demo = new AeadDemo();
54+
AesEaxWithGeneratedKey demo = new AesEaxWithGeneratedKey();
5555

5656
try {
5757
KeysetHandle keysetHandle = demo.generateKey();
@@ -66,7 +66,7 @@ public static void main(String[] args) {
6666
}
6767

6868
private KeysetHandle generateKey() throws GeneralSecurityException {
69-
return KeysetHandle.generateNew(AeadKeyTemplates.AES128_GCM);
69+
return KeysetHandle.generateNew(AeadKeyTemplates.AES256_EAX);
7070
}
7171

7272
private byte[] encrypt(KeysetHandle keysetHandle) throws GeneralSecurityException {

crypto-tink/src/main/java/de/dominikschadow/javasecurity/tink/symmetric/AeadWithSavedKeyDemo.java renamed to crypto-tink/src/main/java/de/dominikschadow/javasecurity/tink/aead/AesGcmWithSavedKey.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package de.dominikschadow.javasecurity.tink.symmetric;
18+
package de.dominikschadow.javasecurity.tink.aead;
1919

2020
import com.google.crypto.tink.*;
2121
import com.google.crypto.tink.aead.AeadConfig;
@@ -31,20 +31,20 @@
3131

3232
/**
3333
* Shows crypto usage with Google Tink for the Authenticated Encryption with Associated Data (AEAD) primitive. The used
34-
* key is stored and loaded from the project.
34+
* key is stored and loaded from the project. Selected algorithm is AES-GCM with 128 bit.
3535
*
3636
* @author Dominik Schadow
3737
*/
38-
public class AeadWithSavedKeyDemo {
39-
private static final Logger log = LoggerFactory.getLogger(AeadWithSavedKeyDemo.class);
38+
public class AesGcmWithSavedKey {
39+
private static final Logger log = LoggerFactory.getLogger(AesGcmWithSavedKey.class);
4040
private static final String INITIAL_TEXT = "Some dummy text to work with";
4141
private static final String ASSOCIATED_DATA = "Some additional data";
42-
private static final String KEYSET_FILENAME = "crypto-tink/src/main/resources/keysets/aead-keyset.json";
42+
private static final String KEYSET_FILENAME = "crypto-tink/src/main/resources/keysets/aead-aes-gcm.json";
4343

4444
/**
4545
* Init AeadConfig in the Tink library.
4646
*/
47-
private AeadWithSavedKeyDemo() {
47+
private AesGcmWithSavedKey() {
4848
try {
4949
AeadConfig.register();
5050
} catch (GeneralSecurityException ex) {
@@ -53,7 +53,7 @@ private AeadWithSavedKeyDemo() {
5353
}
5454

5555
public static void main(String[] args) {
56-
AeadWithSavedKeyDemo demo = new AeadWithSavedKeyDemo();
56+
AesGcmWithSavedKey demo = new AesGcmWithSavedKey();
5757

5858
try {
5959
demo.generateAndStoreKey();

crypto-tink/src/main/resources/keysets/aead-keyset.json renamed to crypto-tink/src/main/resources/keysets/aead-aes-gcm.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"primaryKeyId": 1440325542,
2+
"primaryKeyId": 82246046,
33
"key": [{
44
"keyData": {
55
"typeUrl": "type.googleapis.com/google.crypto.tink.AesGcmKey",
66
"keyMaterialType": "SYMMETRIC",
7-
"value": "GhD4G2gwsdYdOU4ftzbl0Lol"
7+
"value": "GhDjKEsbViapDSSELJV2+g5L"
88
},
99
"outputPrefixType": "TINK",
10-
"keyId": 1440325542,
10+
"keyId": 82246046,
1111
"status": "ENABLED"
1212
}]
1313
}

0 commit comments

Comments
 (0)