有谁会写java的Blowfish-CBC加密算法吗?
public class BlowfishAlgorithmEncryptor
{
public static final Integer BLOWFISH_IVLENGTH = 8;
public static final Integer BLOWFISH_KEYSIZE = 128;
public static final String BLOWFISH_ALGORITHM = "Blowfish";
public static final String BLOWFISH_CBC_PKCS5PADDING = "Blowfish/CBC/PKCS5Padding";
private Key key;
public Key initialKey()
{
try
{
KeyGenerator keyGenerator = KeyGenerator
.getInstance(BLOWFISH_ALGORITHM);
keyGenerator.init(BLOWFISH_KEYSIZE.intValue());
key = keyGenerator.generateKey();
}
catch (NoSuchAlgorithmException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return key;
}
public byte[] encrypt(byte[] plainBytes)
{
try
{
ByteArrayInputStream inputStream = new ByteArrayInputStream(
plainBytes);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
SecureRandom random = new SecureRandom();
byte[] iv = new byte[BLOWFISH_IVLENGTH];
random.nextBytes(iv);
Cipher cipher = getCipher(Cipher.ENCRYPT_MODE, iv);
outputStream.write(iv);
CipherOutputStream cipherStream = new CipherOutputStream(
outputStream, cipher);
for (int i = inputStream.read(); i != -1; i = inputStream.read())
{
cipherStream.write(i);
}
inputStream.close();
cipherStream.close();
outputStream.close();
return outputStream.toByteArray();
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public byte[] decrypt(byte[] cipherBytes)
{
try
{
ByteArrayInputStream inputStream = new ByteArrayInputStream(
cipherBytes);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] iv = new byte[BLOWFISH_IVLENGTH];
inputStream.read(iv);
Cipher cipher = getCipher(Cipher.DECRYPT_MODE, iv);
CipherInputStream cipherStream = new CipherInputStream(inputStream,
cipher);
for (int i = cipherStream.read(); i != -1; i = cipherStream.read())
{
outputStream.write(i);
}
inputStream.close();
cipherStream.close();
outputStream.close();
return outputStream.toByteArray();
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
private Cipher getCipher(int mode, byte[] iv)
{
IvParameterSpec spec = new IvParameterSpec(iv);
try
{
Cipher cipher = Cipher.getInstance(BLOWFISH_CBC_PKCS5PADDING);
cipher.init(mode, key, spec);
return cipher;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
}
TrueCrypt是全球最著名、最权威的硬盘加密软件之一?
TrueCrypt是全球最著名、最权威的硬盘加密软件之一,迄今为止没有任何方法可以破解其加密的磁盘。
它拥有AES-256、Blowfish(448-bitkey)、CAST5、Serpent、Triple DES三种加密算法。
支持长密码,如果长度为20位,暴力破解需要1056993066125年时间!它的加密方式有三种:将文件虚拟为分区来加密,对分区乃至整个硬盘加密,对操作系统加密。
本文将选用其中的分区加密。
运行下载回来的TrueCrypt Setup 6.2a.exe,可选择“Install”(安装)、“Extract”(解压)。
考虑到还要将其拷贝到移动硬盘上使用,请选择“Extract”,直到完成。
接着,将中文补丁解压,再拷贝到TrueCrypt的解压目录。
然后运行解压目录中的TrueCrypt,在程序主界面上单击“Settings”下的“Language”,再选择简体中文,整个程序即可中文化。
加密算法之BLOWFISH算法有何特点
AES-256和RSA-2048绝对可以,用RSA加密密匙,AES加密数据,因为非对称算法加密数据速度实在太慢,所以用非对称算法加密数据根本行不通,但是安全性非常高。