更新加密和解密的模块

This commit is contained in:
YuCheng Hu 2023-02-03 16:06:34 -05:00
parent 605a887041
commit 4ee8318869
2 changed files with 34 additions and 2 deletions

13
pom.xml
View File

@ -35,13 +35,24 @@
</developers>
<dependencies>
<dependency>
<groupId>com.google.doubleclick</groupId>
<artifactId>doubleclick-openrtb</artifactId>
<version>2.0.4-SNAPSHOT</version>
<type>pom</type>
</dependency>
<!-- LOGGING WITH SELF4J AND LOG4J2 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>

View File

@ -1,11 +1,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.io.IOException;
/**
* @author YuCheng
@ -28,6 +32,23 @@ public class GoogleEncryptionService {
*/
public String decryptPrice(String url) {
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"));
} catch (InvalidKeyException e) {
throw new RuntimeException(e);
}
DoubleClickCrypto.Price crypto = new DoubleClickCrypto.Price(keys);
// String encodedPrice = httpRequest.getHeader("price");
// double price = crypto.decodePriceValue(encodedPrice);
return "my-decryptPrice-String";
}