java或者go算法转PHP实现

题目描述

Java代码转PHP解出来总是乱码,请大佬支招。

相关代码

价格加密
价格加密采用 google 自定义的加密机制

https://developers.google.com...

wiki:https://github.com/google/ope...

public class WinnoticeUtil {

public static final byte[] KEY1 = "kingsoft".getBytes();

public static final byte[] KEY2 = "adx".getBytes();

public static final BigDecimal ZERO = new BigDecimal(0);

public static final BigDecimal ONEHUNDRED = new BigDecimal(100);

public static DoubleClickCrypto.Price clickCrypto = null;

static {

try {

DoubleClickCrypto.Keys keys = new DoubleClickCrypto.Keys(

new SecretKeySpec(KEY1, "HmacSHA1"),

new SecretKeySpec(KEY2, "HmacSHA1")

);

clickCrypto = new DoubleClickCrypto.Price(keys);

} catch (Exception e) {

e.printStackTrace();

}

}

public static String encrytPrice(BigDecimal price) {

if (price == null) {

price = ZERO;

}

return clickCrypto.encodePriceValue(price.multiply(ONEHUNDRED).doubleValue(), null);

}

public static String encrytPrice(String price) {

if (price == null) {

return encrytPrice(ZERO);

}

return encrytPrice(new BigDecimal(price));

}

public static String replacePrice(String url, Object... param) {

if (StringUtils.isEmpty(url)) {

return "";

}

return MessageFormat.format(url, param);

}

public static List<String> replaceUrls(List<String> urls, String price) {

if (price == null) {

return replaceUrls(urls, ZERO);

}

return replaceUrls(urls, new BigDecimal(price));

}

public static List<String> replaceUrls(List<String> urls, BigDecimal price) {

List<String> replaceUrls = Lists.newArrayList();

if (CollectionUtils.isEmpty(urls)) {

return replaceUrls;

}

for (String url : urls) {

replaceUrls.add(replacePrice(url, encrytPrice(price)));

}

return replaceUrls;

}

public static void main(String[] args) throws SignatureException {

//加密

String cryptoStr = clickCrypto.encodePriceValue(12,null);

System.out.println(cryptoStr);

//解密

System.out.println(clickCrypto.decodePriceValue(cryptoStr));

}

}

输出

XJwszwAM1ShpYgxpFjZCHnpjOT-uc5s7eH0PzA==

12

以上是 java或者go算法转PHP实现 的全部内容, 来源链接: utcz.com/p/944272.html

回到顶部