La Cryptographie à Courbe elliptique (ECC) avec château gonflable pour le chiffrement asymétrique

Je veux utiliser ECC afin d'échanger une Clé de Session pour une longue durée de transmission de données. Cet échange de clés doit être chiffré à l'aide de l'ECC-192bit (curvename: prime192v1). Cela signifie que je veux mettre en œuvre un chiffrement hybride modèle.

J'ai donc utilisé château gonflable pour JAVA. J'ai mis en place ECDSA et il fonctionne très bien. J'ai implémenté l'algorithme AES 128 bits de cryptage symétrique et cela fonctionne aussi très bien. Mais je ne peux pas mettre en œuvre un simple chiffrement Asymétrique à l'aide de l'ECC.

Donc ma question: est-ce le chiffrement asymétrique mis en œuvre avec château gonflable?

C'est ma essayer de mettre en œuvre un chiffrement ECC à l'aide de la AsymmetricBlockCipher interface. Mais cela ne fonctionne pas.

Dois-je vraiment mettre en place mes propres ECCEngine comme il y a une mise en œuvre pour la RSAEngine (RSACoreEngin)?

Voici mon code:

import org.bouncycastle.jce.interfaces.ECPublicKey;
import org.bouncycastle.jce.interfaces.ECPrivateKey;
import org.bouncycastle.crypto.AsymmetricBlockCipher;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.engines.AESEngine;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.jce.spec.ECParameterSpec;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import javax.crypto.Cipher;
public class ASymCrypto {
//cipher init
private static AsymmetricBlockCipher bc = null;
//   private static PaddedBufferedBlockCipher cipher = null;
//keys and info parameter
private static ECPublicKeyParameters publicParam = null;
private static ECPrivateKeyParameters privParam = null;
/**
* Constructor
*/
ASymCrypto(ECPublicKey pubKey, ECPrivateKey privKey) {
// //default paddedBufferedBlockCipher with PKCS5/7 padding
// cipher = new PaddedBufferedBlockCipher(bc);
System.out.println( "remotePrivateKey:  " + privKey + " -(format): "+ privKey.getFormat() + " algo: " + privKey.getAlgorithm());
System.out.println( "remotePrivateKey:  " + pubKey + " -(format): "+ pubKey.getFormat() + " algo: " + pubKey.getAlgorithm());
//get the key and the EC parameters
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("prime192v1");
ECDomainParameters domainParam = new ECDomainParameters(
ecSpec.getCurve() , 
ecSpec.getG(), 
ecSpec.getN());
//ECPublicKeyParameters(ECPoint Q, ECDomainParameters params) 
publicParam = new ECPublicKeyParameters( pubKey.getQ() , domainParam );
if(publicParam == null)
System.out.println("ERROR: Initializing ASymCrpto failed at ECPublicKeyParam.");
//ECPrivateKeyParameters(java.math.BigInteger d, ECDomainParameters params) 
privParam = new ECPrivateKeyParameters( privKey.getD(), domainParam );
if(privParam == null)
System.out.println("ERROR: Initializing ASymCrpto failed at ECPrivateKeyParam.");
bc = new AsymmetricBlockCipher(new AESEngine());
}
/**
*  encryptEC192 function
*  @param input: byte array with the message to encrypt
*  @param output: byte array with the encrypted message using the public key of the partner
*  @return bool true if successfully encrypted
*  @throws InvalidCipherTextException 
*/
public boolean encryptEC192(byte[] input, byte[] output) throws InvalidCipherTextException{
if(publicParam == null)
System.out.println("ERROR2: Initializing ASymCrpto failed at ECPublicKeyParam.");
bc.init( true, publicParam);
System.out.println("InputBS: " + bc.getInputBlockSize() + " OutputBS: " + bc.getOutputBlockSize() + "\n");
output = bc.processBlock(input, 0, input.length );
return true;
}
/**
*  encryptEC192 function
*  @param input: byte array with the message to encrypt
*  @param output: byte array with the encrypted message using the public key of the partner
*  @return bool true if successfully encrypted
*  @throws InvalidCipherTextException 
*/    
public boolean decryptEC192(byte[] input, byte[] output) throws InvalidCipherTextException{
if(privParam == null)
System.out.println("ERROR2: Initializing ASymCrpto failed at ECPrivateKeyParam.");
bc.init( false, privParam);
System.out.println("InputBS: " + bc.getInputBlockSize() + " OutputBS: " + bc.getOutputBlockSize() + "\n");
output = bc.processBlock(input, 0, input.length );
return true;
}
// INFORMATION PURPOSE ONLY:
// public byte[] processBlock(byte[] in,
//                            int inOff,
//                            int len)
//                     throws InvalidCipherTextException
// process the block of len bytes stored in in from offset inOff.
// Parameters:
// in - the input data
// inOff - offset into the in array where the data starts
// len - the length of the block to be processed.
// Returns:
// the resulting byte array of the encryption/decryption process.
// Throws:
// InvalidCipherTextException - data decrypts improperly.
// DataLengthException - the input data is too large for the cipher.
}
Êtes-vous sûr de savoir Java assez bien? Vous essayez de traiter une interface comme une classe et qu'ils ne sont pas la même chose. Vous n'avez pas n'importe quel code à tous de faire le cryptage. Êtes-vous sûr que vous comprenez la courbe elliptique crypto assez bien pour le faire?
Thanky pour la réponse et sry pour la réponse tardive. Oui, je connais la différence entre une interface et une classe. Cet exemple de code ci-dessus ne devrait expliquer à ma question et est pleine d'erreurs et de ne pas se terminer. Sinon je mettre en place mon propre CE Moteur de ce qui va être vraiment un défi pour moi, mais pas impossible, je pense. Si je comprends courbe elliptique crypto assez bien? C'est ma question. Je préférerait évidemment une mise en œuvre de l'API solution. Et je voudrais savoir si il y en a un déjà existant?

OriginalL'auteur Manuel | 2011-05-18