import java.security.InvalidKeyException;
import java.security.SecureRandom;import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;class PBDemo {
public static void main(String args[]) throws InvalidKeyException,
Exception {
String strKey = "123456"; //密钥
byte[] byteE = "helloworld".getBytes(); //需要机密的字符串
byte[] byteFina = null;
Cipher cipher = null;
try {
cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, generatorKey(strKey));
byteFina = cipher.doFinal(byteE);
} finally {
cipher = null;
}
//byteFina写入文件

System.out.println(new String(byteFina));
} /**
 * 生成密钥
 * @param skey
 * @return
 * @throws Exception
 */
public static SecretKeySpec generatorKey(String skey) throws Exception {
KeyGenerator kGen = KeyGenerator.getInstance("AES");
SecureRandom secRandom = SecureRandom.getInstance("SHA1PRNG");
secRandom.setSeed(skey.getBytes());
kGen.init(128, secRandom);
SecretKey key = kGen.generateKey();
byte[] enCodeFormat = key.getEncoded();
SecretKeySpec specKey = new SecretKeySpec(enCodeFormat, "AES");
kGen = null;
return specKey;
}
}
这段代码是使用java写的,目的就是产生一个加密用的密钥,求达人指教,如何用C#或VC或VB之类的重写这个generatorKey加密算法