PDA

View Full Version : [C#] bouncycastle problema assenza di alcune classi


toni00t
15-11-2014, 17:48
ciao: sto implementando ad alto livello un codice di java che utilizza le librerie bouncycastle : mancano alcune classi nella versione c# di bouncycastle , tra cui,e qui è il mio problema , IEScipher
qualcuno sa come rimpiazzarla in questo codice nella versione c#?


public void test() throws Exception {
KeyPair keyPair = getKeyPair();
ECPublicKey publicKey = (ECPublicKey) keyPair.getPublic();
ECPrivateKey privateKey = (ECPrivateKey) keyPair.getPrivate();

IESEngine e1 = getEciesAesCbcEngine();
IESEngine e2 = getEciesAesCbcEngine();
IESCipher c1 = new IESCipher(e1); //here is the problem
IESCipher c2 = new IESCipher(e2);

c1.engineSetMode("DHAES");
c2.engineSetMode("DHAES");

int macKeySize = 256; // #2
int cipherKeySize = 256; // #3
IESParameterSpec parameterSpec = new IESParameterSpec(null, null, macKeySize, cipherKeySize);
c1.engineInit(ENCRYPT_MODE, publicKey, parameterSpec, new SecureRandom());
c2.engineInit(DECRYPT_MODE, privateKey, parameterSpec, new SecureRandom());


byte[] message = "hello world -- a nice day today".getBytes();
byte[] ciphertext = c1.engineDoFinal(message, 0, message.length);
System.out.println("length: " + ciphertext.length);
byte[] plaintext = c2.engineDoFinal(ciphertext, 0, ciphertext.length);
System.out.println(new String(plaintext));

IESParameterSpec spec1 = IESUtil.guessParameterSpec(e1);
System.out.println("cipher key size: " + spec1.getCipherKeySize());
System.out.println("mac key size: " + spec1.getMacKeySize());
}