sh 1 prngアルゴリズム
1305 ワード
/**
* @return cookie v=1&u=xxx&a=1
*/
public String generateEncodeValue() {
StringBuffer encodeValue = new StringBuffer();
encodeValue.append("v=").append(this.version).append("|u=")
.append(this.uid).append("|a=").append(this.autoLogin);
try {
String key = CMCrypto.initKey(seed);
String value = CMHash.encryptBASE64(CMCrypto.encrypt(encodeValue
.toString().getBytes(), key));
value = value.replaceAll("\r", "<");
value = value.replaceAll("
", ">");
return value;
} catch (Exception e) {
LogNew.fatal("crypto cookie fail.", e);
}
return "";
}
public static String initKey(String seed) throws Exception {
KeyGenerator kg = KeyGenerator.getInstance(ALGORITHM);
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(seed.getBytes());
kg.init(128, secureRandom);
SecretKey secretKey = kg.generateKey();
return CMHash.encryptBASE64(secretKey.getEncoded());
}