测试加密和解密
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.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.doubleclick.crypto.DoubleClickCrypto;
|
import com.google.doubleclick.crypto.DoubleClickCrypto;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Base64Utils;
|
import org.springframework.util.Base64Utils;
|
||||||
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.SignatureException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,14 +40,25 @@ public class GoogleEncryptionService {
|
|||||||
;
|
;
|
||||||
DoubleClickCrypto.Keys keys = null;
|
DoubleClickCrypto.Keys keys = null;
|
||||||
try {
|
try {
|
||||||
keys = new DoubleClickCrypto.Keys(
|
keys = new DoubleClickCrypto.Keys(new SecretKeySpec(Base64Utils.encode(encryptionKey.getBytes()), "HmacSHA1"), new SecretKeySpec(Base64Utils.encode(integrityKey.getBytes()), "HmacSHA1"));
|
||||||
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) {
|
} catch (InvalidKeyException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} catch (SignatureException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
DoubleClickCrypto.Price crypto = new DoubleClickCrypto.Price(keys);
|
|
||||||
|
|
||||||
// String encodedPrice = httpRequest.getHeader("price");
|
// String encodedPrice = httpRequest.getHeader("price");
|
||||||
// double price = crypto.decodePriceValue(encodedPrice);
|
// double price = crypto.decodePriceValue(encodedPrice);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user