sh1prng算法
/** * @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("\n", ">"); 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()); }
相关推荐
湾区人工智能 2020-11-20
Pokemogo 2020-11-16
baijingjing 2020-11-16
baijingjing 2020-11-15
Site 2020-11-07
lwnylslwnyls 2020-11-06
justaipanda 2020-11-05
MachineIntellect 2020-11-02
xueyuediana 2020-10-30
GeraldJones 2020-10-30
Tips 2020-10-29
baijingjing 2020-10-28
baijingjing 2020-10-27
硕鼠 2020-10-26
playoffs 2020-10-26
scuyxi 2020-10-25
playoffs 2020-10-25
yise001 2020-10-23