1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
static final byte[] iv8 = { (byte) 0xc9, (byte) 0x36, (byte) 0x78,
(byte) 0x99, (byte) 0x52, (byte) 0x3e, (byte) 0xea, (byte) 0xf2 };
Certificat cert; // certificat RSA de cryptage
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede");
SecretKey symkey = keyGenerator.generateKey();
IvParameterSpec salt = new IvParameterSpec(iv8);
Cipher c = Cipher.getInstance("DESede/CBC/NoPadding", "BC");
c.init(Cipher.ENCRYPT_MODE, symkey, salt);
// chiffrement de la clef symétrique par RSA
Cipher pbb = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC");
pbb.init(Cipher.WRAP_MODE, cert.getPublicKey());
// chiffrement du fichier de données par la clef symétrique et sortie
FileOutputStream fsout = new FileOutputStream(...);
fsout.write(pbb.wrap(symkey));
fsout.write(c.doFinal(...à_crypter...));
fsout.write(salt.getIV());
fsout.close(); |
Partager