@Test public void testEncryptBallot() throws Exception { initBallotCiphersProviderMock(); StringBuilder sb = new StringBuilder(); sb.append("GE;6699:9903"); sb.append("370001;0;37000101;p=DEP"); sb.append(Strings.repeat(";1001", 545)); AuthenticatedBallot authenticatedBallot = ballotCipherService.encryptBallotThenWrapForAuthentication(sb.toString(), 1); assertThat("The encrypted ballot byte array length should be less than 4000 chars", authenticatedBallot.getAuthenticatedEncryptedBallot().length, lessThan(4000)); assertThat("The encrypted ballot key should be 256 bytes long", authenticatedBallot.getWrappedKey().length, is(256)); assertThat("The encryption authentication tag should be 128bit / 16 bytes long", authenticatedBallot.getTag().length, is(16)); assertThat("The authenticated ballot should have the proper index attached", authenticatedBallot.getBallotIndex(), is(1)); }
public AuthenticatedBallot encryptBallotThenWrapForAuthentication(String plainText, int ballotIndex) { Cipher ballotKeyCipher = ciphersProvider.getBallotKeyCipher(); Cipher ballotCipher = ciphersProvider.getBallotCipher(); Key plainSymmetricKey = createNewRandomSymmetricKey(ballotCipher); byte[] encryptedBallot = doFirstLayerEncryption(plainText, ballotCipher, plainSymmetricKey); Key integrityKey = ciphersProvider.getIntegrityCheckSecretKey(); Cipher integrityCipher = ciphersProvider.getIntegrityCipher(propertyConfigurationService); byte[] authenticatedBallot = aeadEncrypt(integrityCipher, integrityKey, ballotIndex, encryptedBallot); byte[] tag = Arrays.copyOfRange(authenticatedBallot, authenticatedBallot.length - (AEAD_TAG_SIZE / Byte.SIZE), authenticatedBallot.length); byte[] wrappedKey = wrapKey(ballotKeyCipher, plainSymmetricKey); return new AuthenticatedBallot(wrappedKey, authenticatedBallot, ballotIndex, tag); }
BallotCipherService { public AuthenticatedBallot encryptBallotThenWrapForAuthentication(String plainText, int ballotIndex) { Cipher ballotKeyCipher = ciphersProvider.getBallotKeyCipher(); Cipher ballotCipher = ciphersProvider.getBallotCipher(); Key plainSymmetricKey = createNewRandomSymmetricKey(ballotCipher); byte[] encryptedBallot = doFirstLayerEncryption(plainText, ballotCipher, plainSymmetricKey); Key integrityKey = ciphersProvider.getIntegrityCheckSecretKey(); Cipher integrityCipher = ciphersProvider.getIntegrityCipher(propertyConfigurationService); byte[] authenticatedBallot = aeadEncrypt(integrityCipher, integrityKey, ballotIndex, encryptedBallot); byte[] tag = Arrays.copyOfRange(authenticatedBallot, authenticatedBallot.length - (AEAD_TAG_SIZE / Byte.SIZE), authenticatedBallot.length); byte[] wrappedKey = wrapKey(ballotKeyCipher, plainSymmetricKey); return new AuthenticatedBallot(wrappedKey, authenticatedBallot, ballotIndex, tag); } }
BallotCipherService { public AuthenticatedBallot encryptBallotThenWrapForAuthentication(String plainText, int ballotIndex) { Cipher ballotKeyCipher = ciphersProvider.getBallotKeyCipher(); Cipher ballotCipher = ciphersProvider.getBallotCipher(); Key plainSymmetricKey = createNewRandomSymmetricKey(ballotCipher); byte[] encryptedBallot = doFirstLayerEncryption(plainText, ballotCipher, plainSymmetricKey); Key integrityKey = ciphersProvider.getIntegrityCheckSecretKey(); Cipher integrityCipher = ciphersProvider.getIntegrityCipher(propertyConfigurationService); byte[] authenticatedBallot = aeadEncrypt(integrityCipher, integrityKey, ballotIndex, encryptedBallot); byte[] tag = Arrays.copyOfRange(authenticatedBallot, authenticatedBallot.length - (AEAD_TAG_SIZE / Byte.SIZE), authenticatedBallot.length); byte[] wrappedKey = wrapKey(ballotKeyCipher, plainSymmetricKey); return new AuthenticatedBallot(wrappedKey, authenticatedBallot, ballotIndex, tag); } BallotCipherService(BallotCiphersProvider ciphersProvider, PropertyConfigurationService propertyConfigurationService); }
BallotCipherService { public AuthenticatedBallot encryptBallotThenWrapForAuthentication(String plainText, int ballotIndex) { Cipher ballotKeyCipher = ciphersProvider.getBallotKeyCipher(); Cipher ballotCipher = ciphersProvider.getBallotCipher(); Key plainSymmetricKey = createNewRandomSymmetricKey(ballotCipher); byte[] encryptedBallot = doFirstLayerEncryption(plainText, ballotCipher, plainSymmetricKey); Key integrityKey = ciphersProvider.getIntegrityCheckSecretKey(); Cipher integrityCipher = ciphersProvider.getIntegrityCipher(propertyConfigurationService); byte[] authenticatedBallot = aeadEncrypt(integrityCipher, integrityKey, ballotIndex, encryptedBallot); byte[] tag = Arrays.copyOfRange(authenticatedBallot, authenticatedBallot.length - (AEAD_TAG_SIZE / Byte.SIZE), authenticatedBallot.length); byte[] wrappedKey = wrapKey(ballotKeyCipher, plainSymmetricKey); return new AuthenticatedBallot(wrappedKey, authenticatedBallot, ballotIndex, tag); } BallotCipherService(BallotCiphersProvider ciphersProvider, PropertyConfigurationService propertyConfigurationService); AuthenticatedBallot encryptBallotThenWrapForAuthentication(String plainText, int ballotIndex); EncryptedBallotAndWrappedKey verifyAuthenticationThenUnwrap(AuthenticatedBallot authenticatedBallot); String decryptBallot(EncryptedBallotAndWrappedKey encryptedBallotAndWrappedKey); void loadBallotKeyCipherPrivateKey(String password); void setPrivateKeyFileName(String privateKeyFileName); void setPublicKeyFileName(String publicKeyFileName); void setIntegrityKeyFileName(String integrityKeyFileName); }
BallotCipherService { public AuthenticatedBallot encryptBallotThenWrapForAuthentication(String plainText, int ballotIndex) { Cipher ballotKeyCipher = ciphersProvider.getBallotKeyCipher(); Cipher ballotCipher = ciphersProvider.getBallotCipher(); Key plainSymmetricKey = createNewRandomSymmetricKey(ballotCipher); byte[] encryptedBallot = doFirstLayerEncryption(plainText, ballotCipher, plainSymmetricKey); Key integrityKey = ciphersProvider.getIntegrityCheckSecretKey(); Cipher integrityCipher = ciphersProvider.getIntegrityCipher(propertyConfigurationService); byte[] authenticatedBallot = aeadEncrypt(integrityCipher, integrityKey, ballotIndex, encryptedBallot); byte[] tag = Arrays.copyOfRange(authenticatedBallot, authenticatedBallot.length - (AEAD_TAG_SIZE / Byte.SIZE), authenticatedBallot.length); byte[] wrappedKey = wrapKey(ballotKeyCipher, plainSymmetricKey); return new AuthenticatedBallot(wrappedKey, authenticatedBallot, ballotIndex, tag); } BallotCipherService(BallotCiphersProvider ciphersProvider, PropertyConfigurationService propertyConfigurationService); AuthenticatedBallot encryptBallotThenWrapForAuthentication(String plainText, int ballotIndex); EncryptedBallotAndWrappedKey verifyAuthenticationThenUnwrap(AuthenticatedBallot authenticatedBallot); String decryptBallot(EncryptedBallotAndWrappedKey encryptedBallotAndWrappedKey); void loadBallotKeyCipherPrivateKey(String password); void setPrivateKeyFileName(String privateKeyFileName); void setPublicKeyFileName(String publicKeyFileName); void setIntegrityKeyFileName(String integrityKeyFileName); static final int AEAD_TAG_SIZE; }