Skip to content

Commit

Permalink
minor changes to new encryption methods (CFB, CTR, ECB emulation)
Browse files Browse the repository at this point in the history
  • Loading branch information
pteufl committed Nov 25, 2015
1 parent 9c0adb9 commit 434bc56
Show file tree
Hide file tree
Showing 2 changed files with 264 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ protected void updateTurnOverCounterAndAddToDataToBeSigned(ReceiptRepresentation

//ATTENTION: changes made to procedure on how to sum up/round values for turnover counter
//PREV: sum up values, round them, add them to turnover counter
//NOW: to simplify procedures: turnover counter changed to €-cent. before: 100€ were represented as 100, now
//NOW: to simplify procedures: turnover counter changed to -cent. before: 100 were represented as 100, now
//they are represented as 10000
double tempSum = 0.0;
tempSum += sumTaxTypeNormal;
Expand All @@ -297,7 +297,7 @@ protected void updateTurnOverCounterAndAddToDataToBeSigned(ReceiptRepresentation
tempSum += sumTaxTypeBesonders;
tempSum += sumTaxTypeNull;

//NEW METHOD: convert sum to €-cent and add to turnover counter
//NEW METHOD: convert sum to -cent and add to turnover counter
turnoverCounter += (tempSum * 100);

//OLD METHOD: DO NOT USE
Expand Down Expand Up @@ -332,13 +332,20 @@ protected void updateTurnOverCounterAndAddToDataToBeSigned(ReceiptRepresentation
//support selected AES modes of operation only. Please refer to
//https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation for more details
//on different modes of operation for block ciphers
String base64EncryptedTurnOverValue = AESUtil.encryptCTR(concatenatedHashValue, turnoverCounter, cashBoxParameters.getTurnoverKeyAESkey());
//String base64EncryptedTurnOverValue = AESUtil.encryptCFB(concatenatedHashValue, turnoverCounter, cashBoxParameters.getTurnoverKeyAESkey());
//String base64EncryptedTurnOverValue = AESUtil.encryptECB(concatenatedHashValue, turnoverCounter, cashBoxParameters.getTurnoverKeyAESkey());

String base64EncryptedTurnOverValue1 = AESUtil.encryptCTR(concatenatedHashValue, turnoverCounter, cashBoxParameters.getTurnoverKeyAESkey());
String base64EncryptedTurnOverValue2 = AESUtil.encryptCFB(concatenatedHashValue, turnoverCounter, cashBoxParameters.getTurnoverKeyAESkey());
String base64EncryptedTurnOverValue3 = AESUtil.encryptECB(concatenatedHashValue, turnoverCounter, cashBoxParameters.getTurnoverKeyAESkey());
if (!base64EncryptedTurnOverValue1.equals(base64EncryptedTurnOverValue2)) {
System.out.println("ENCRYPTION ERROR IN METHOD updateTurnOverCounterAndAddToDataToBeSigned, MUST NOT HAPPEN");
System.exit(-1);
}
if (!base64EncryptedTurnOverValue1.equals(base64EncryptedTurnOverValue3)) {
System.out.println("ENCRYPTION ERROR IN METHOD updateTurnOverCounterAndAddToDataToBeSigned, MUST NOT HAPPEN");
System.exit(-1);
}

//set encrypted turnovervalue in data-to-be-signed datastructure
receiptRepresentationForSignature.setEncryptedTurnoverValue(base64EncryptedTurnOverValue);
receiptRepresentationForSignature.setEncryptedTurnoverValue(base64EncryptedTurnOverValue1);

//THE FOLLOWING CODE IS ONLY FOR DEMONSTRATION PURPOSES
//decryption and reconstruction of the turnover value
Expand All @@ -354,13 +361,22 @@ protected void updateTurnOverCounterAndAddToDataToBeSigned(ReceiptRepresentation
//support selected AES modes of operation only. Please refer to
//https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation for more details
//on different modes of operation for block ciphers
long testPlainOverTurnOverReconstructed = AESUtil.decryptCTR(concatenatedHashValue, base64EncryptedTurnOverValue, cashBoxParameters.getTurnoverKeyAESkey());
//long testPlainOverTurnOverReconstructed = AESUtil.decryptCFB(concatenatedHashValue, base64EncryptedTurnOverValue, cashBoxParameters.getTurnoverKeyAESkey());
//long testPlainOverTurnOverReconstructed = AESUtil.decryptECB(concatenatedHashValue, base64EncryptedTurnOverValue, cashBoxParameters.getTurnoverKeyAESkey());

long testPlainOverTurnOverReconstructed1 = AESUtil.decryptCTR(concatenatedHashValue, base64EncryptedTurnOverValue1, cashBoxParameters.getTurnoverKeyAESkey());
long testPlainOverTurnOverReconstructed2 = AESUtil.decryptCFB(concatenatedHashValue, base64EncryptedTurnOverValue2, cashBoxParameters.getTurnoverKeyAESkey());
long testPlainOverTurnOverReconstructed3 = AESUtil.decryptECB(concatenatedHashValue, base64EncryptedTurnOverValue3, cashBoxParameters.getTurnoverKeyAESkey());
if (testPlainOverTurnOverReconstructed1 != testPlainOverTurnOverReconstructed2) {
System.out.println("DECRYPTION ERROR IN METHOD updateTurnOverCounterAndAddToDataToBeSigned, MUST NOT HAPPEN");
System.exit(-1);
}

if (testPlainOverTurnOverReconstructed1 != testPlainOverTurnOverReconstructed3) {
System.out.println("DECRYPTION ERROR IN METHOD updateTurnOverCounterAndAddToDataToBeSigned, MUST NOT HAPPEN");
System.exit(-1);
}

if (turnoverCounter != testPlainOverTurnOverReconstructed) {
if (turnoverCounter != testPlainOverTurnOverReconstructed1) {
System.out.println("DECRYPTION ERROR IN METHOD updateTurnOverCounterAndAddToDataToBeSigned, MUST NOT HAPPEN");
System.exit(-1);
}
} catch (NoSuchProviderException | IllegalBlockSizeException | NoSuchPaddingException | InvalidKeyException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | BadPaddingException e) {
e.printStackTrace();
Expand Down
Loading

0 comments on commit 434bc56

Please sign in to comment.