请帮帮我。
我需要将函数加密和解密从Java转换为对象C. 这是加密功能:
byte inBuf[] = outA.toByteArray();
SecretKeyFactory keyFac = SecretKeyFactory.getInstance("DESede");
DESedeKeySpec keySpec = new DESedeKeySpec(passwd.getBytes());
SecretKey secKey = keyFac.generateSecret(keySpec);
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, secKey);
cipher.init(Cipher.ENCRYPT_MODE, secKey);
byte[] b = cipher.doFinal(inBuf);
这是功能解密:
static public byte[] dec(byte data[]){
byte[] ret = null;
SecretKeyFactory keyFac;
keyFac = SecretKeyFactory.getInstance("DESede");
DESedeKeySpec keySpec = new DESedeKeySpec(passwd.getBytes());
SecretKey secKey = keyFac.generateSecret(keySpec);
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.DECRYPT_MODE, secKey);
ret = cipher.doFinal(data);
return ret;
}
感谢。