Skip to content

Instantly share code, notes, and snippets.

@stefan2904
Created September 12, 2014 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefan2904/b82858e688a904b1a297 to your computer and use it in GitHub Desktop.
Save stefan2904/b82858e688a904b1a297 to your computer and use it in GitHub Desktop.
things are strange sometimes.
package iaik.pgp.demos;
import iaik.pgp.exceptions.PGPException;
import iaik.pgp.utils.HexConverter;
import iaik.security.provider.IAIK;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class OpenPGP_CFB_demo {
private static final byte[] keyData = { (byte) 0xd6, (byte) 0xf4, (byte) 0x4e, (byte) 0x5e, (byte) 0xdc,
(byte) 0xc0, (byte) 0x48, (byte) 0xc3, (byte) 0x15, (byte) 0x24, (byte) 0xc2, (byte) 0x53, (byte) 0x53,
(byte) 0x6d, (byte) 0x35, (byte) 0x12, (byte) 0x6b, (byte) 0x24, (byte) 0xd7, (byte) 0xe5, (byte) 0xe9,
(byte) 0x22, (byte) 0x88, (byte) 0xd6 };
public static Cipher getCipher(int opmode, String cipherName) throws PGPException {
Cipher cipher;
try {
SecretKeySpec secretKeySpec = new SecretKeySpec(keyData, "AES");
cipher = Cipher.getInstance(cipherName);
byte[] iv = new byte[cipher.getBlockSize()];
cipher.init(opmode, secretKeySpec, new IvParameterSpec(iv));
} catch (InvalidKeyException | InvalidAlgorithmParameterException | NoSuchAlgorithmException
| NoSuchPaddingException e) {
throw new PGPException("Error initializing symmetric (" + cipherName + ") cipher: ", e);
}
return cipher;
}
public static void main(String[] args) throws PGPException, IllegalBlockSizeException, BadPaddingException {
IAIK.addAsProvider();
byte[] cipehrtext = { (byte) 0xe2, (byte) 0x62, (byte) 0x59, (byte) 0xa4, (byte) 0x0d, (byte) 0xe2,
(byte) 0xf9, (byte) 0xc3, (byte) 0x9c, (byte) 0x68, (byte) 0x8b, (byte) 0xe4, (byte) 0x13, (byte) 0x5f,
(byte) 0x36, (byte) 0x5d, (byte) 0x33, (byte) 0x4e, (byte) 0x5d, (byte) 0x0c, (byte) 0x33, (byte) 0x98,
(byte) 0xaa, (byte) 0x55, (byte) 0x5c, (byte) 0xf3, (byte) 0x99, (byte) 0x3a, (byte) 0xc3, (byte) 0x9c,
(byte) 0x62, (byte) 0x32, (byte) 0x98, (byte) 0xfe, (byte) 0x13, (byte) 0x2c, (byte) 0xc7, (byte) 0x10,
(byte) 0x07, (byte) 0x98, (byte) 0x2e, (byte) 0x07, (byte) 0x5c, (byte) 0x26, (byte) 0x9a, (byte) 0x8a,
(byte) 0x71, (byte) 0x26, (byte) 0x23, (byte) 0xdb, (byte) 0xa0, (byte) 0xd2, (byte) 0xc3, (byte) 0x8b,
(byte) 0x94, (byte) 0x79, (byte) 0xf7, (byte) 0x2a, (byte) 0x83, (byte) 0xb0 };
Cipher cfb = getCipher(Cipher.DECRYPT_MODE, "AES/CFB/NoPadding");
Cipher openpgp_cfb = getCipher(Cipher.DECRYPT_MODE, "AES/OpenPGPCFB/NoPadding");
System.out.println(" CFB: " + HexConverter.byteToHex(cfb.doFinal(cipehrtext)));
System.out.println("openPGP CFB: " + HexConverter.byteToHex(openpgp_cfb.doFinal(cipehrtext)));
}
}
@stefan2904
Copy link
Author

Problem, weil:

CFB:

45:db:9a:77:4c:c2:e4:37:01:24:7d:1c:e4:74:c5:66:c5:66:
cb:12:62:00:54:0f:29:22:68:65:6c:6c:6f:20:77:6f:72:6c:64:0a:
d3:14:67:ee:04:e7:28:a9:93:de:b2:29:89:ce:f9:5a:97:0f:9e:ba:99:b1

(richtig?)

openPGP CFB:

45:db:9a:77:4c:c2:e4:37:01:24:7d:1c:e4:74:c5:66:c5:66:
a4:33:b0:ae:3c:97:18:db:0c:b3:3f:36:ca:9d:2d:16:eb:12:c6:
4a:1a:d8:62:dc:c1:78:28:f1:38:b6:69:d6:64:2e:49:b8:27:7b:d7:83:25:76

(falsch?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment