w*******e 发帖数: 285 | 1 我在server和client之间的传输用AES加密解密,String和byte[]之间的转换都用UTF8
编码
public String decrypt(String CipherText) {
try {
byte[] raw = decoder.decodeBuffer(CipherText);
byte[] stringBytes = decrypt_cipher.doFinal(raw);
String PlainText = new String(stringBytes, "UTF8");
return PlainText;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public String encrypt(String PlainText) {
try {
|
m******t 发帖数: 2416 | 2 Are you running multiple encrypting/decrypting threads? |
w*******e 发帖数: 285 | 3
在server端是这样的,每个thread有一个单独的加密的Crypto class,不过变量都是独
立的,这样也会出问题吗?那应该怎么解决呢?整个类的代码如下
public class Crypto{
private SecretKeySpec skey;
private Cipher encrypt_cipher;
private Cipher decrypt_cipher;
private BASE64Decoder decoder;
private BASE64Encoder encoder;
public Crypto(String str_key) {
try {
BASE64Decoder b64decoder = new BASE64Decoder();
this.skey=new SecretKeySpec(b64decoder.decodeBuffer(str_skey),"
AES");
this.encrypt_cipher = C
【在 m******t 的大作中提到】 : Are you running multiple encrypting/decrypting threads?
|
m******t 发帖数: 2416 | 4
Are all these variables assigned on a per-thread basis?
【在 w*******e 的大作中提到】 : : 在server端是这样的,每个thread有一个单独的加密的Crypto class,不过变量都是独 : 立的,这样也会出问题吗?那应该怎么解决呢?整个类的代码如下 : public class Crypto{ : private SecretKeySpec skey; : private Cipher encrypt_cipher; : private Cipher decrypt_cipher; : private BASE64Decoder decoder; : private BASE64Encoder encoder; : public Crypto(String str_key) {
|