Created
September 12, 2014 18:34
-
-
Save stefan2904/b82858e688a904b1a297 to your computer and use it in GitHub Desktop.
things are strange sometimes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem, weil:
CFB:
(richtig?)
openPGP CFB:
(falsch?)