测试加密和解密
This commit is contained in:
parent
4ee8318869
commit
bf7fd2c3e3
@ -3,12 +3,15 @@ package com.ossez.framework.service;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.doubleclick.crypto.DoubleClickCrypto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.SignatureException;
|
||||
import java.util.Base64;
|
||||
|
||||
|
||||
/**
|
||||
@ -32,19 +35,30 @@ public class GoogleEncryptionService {
|
||||
*/
|
||||
public String decryptPrice(String url) {
|
||||
|
||||
String encryptionKey ="encryption";
|
||||
String encryptionKey = "encryption";
|
||||
String integrityKey = "integrityKey";
|
||||
;
|
||||
DoubleClickCrypto.Keys keys = null;
|
||||
try {
|
||||
keys = new DoubleClickCrypto.Keys(
|
||||
new SecretKeySpec(Base64Utils.encode(encryptionKey.getBytes()), "HmacSHA1"),
|
||||
new SecretKeySpec(Base64Utils.encode(integrityKey.getBytes()), "HmacSHA1"));
|
||||
keys = new DoubleClickCrypto.Keys(new SecretKeySpec(Base64Utils.encode(encryptionKey.getBytes()), "HmacSHA1"), new SecretKeySpec(Base64Utils.encode(integrityKey.getBytes()), "HmacSHA1"));
|
||||
|
||||
DoubleClickCrypto.Price crypto = new DoubleClickCrypto.Price(keys);
|
||||
|
||||
|
||||
String price = "2.30";
|
||||
byte[] bA = crypto.encrypt(Base64Utils.encode(price.getBytes()));
|
||||
|
||||
String encodedPrice = Base64.getEncoder().encodeToString(bA);
|
||||
|
||||
double priceEncode = crypto.decodePriceValue(encodedPrice);
|
||||
|
||||
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (SignatureException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
DoubleClickCrypto.Price crypto = new DoubleClickCrypto.Price(keys);
|
||||
|
||||
// String encodedPrice = httpRequest.getHeader("price");
|
||||
// double price = crypto.decodePriceValue(encodedPrice);
|
||||
|
Loading…
x
Reference in New Issue
Block a user