Commit b0513f09 authored by yanzg's avatar yanzg

表结构修改

parent d048f8a5
...@@ -373,12 +373,7 @@ public final class RsaHelper { ...@@ -373,12 +373,7 @@ public final class RsaHelper {
*/ */
public static String decodeRsaValueInfo(String rsaJsonPwd, PublicKey publicKey, long timeout) { public static String decodeRsaValueInfo(String rsaJsonPwd, PublicKey publicKey, long timeout) {
String rsaJson = decryptionByPublicKey(rsaJsonPwd, publicKey); String rsaJson = decryptionByPublicKey(rsaJsonPwd, publicKey);
RsaValueInfo rsaValueInfo = JsonHelper.deserialize(rsaJson, RsaValueInfo.class); return checkTimeout(timeout, rsaJson);
long splitTime = rsaValueInfo.getT() - System.currentTimeMillis() / 1000;
if (splitTime > timeout) {
throw new RuntimeCodeException("056", "解密超时");
}
return rsaValueInfo.getV();
} }
/** /**
...@@ -391,9 +386,13 @@ public final class RsaHelper { ...@@ -391,9 +386,13 @@ public final class RsaHelper {
*/ */
public static String decodeRsaValueInfo(String rsaJsonPwd, PrivateKey privateKey, long timeout) { public static String decodeRsaValueInfo(String rsaJsonPwd, PrivateKey privateKey, long timeout) {
String rsaJson = decryptionByPrivateKey(rsaJsonPwd, privateKey); String rsaJson = decryptionByPrivateKey(rsaJsonPwd, privateKey);
return checkTimeout(timeout, rsaJson);
}
private static String checkTimeout(long timeout, String rsaJson) {
RsaValueInfo rsaValueInfo = JsonHelper.deserialize(rsaJson, RsaValueInfo.class); RsaValueInfo rsaValueInfo = JsonHelper.deserialize(rsaJson, RsaValueInfo.class);
long splitTime = rsaValueInfo.getT() - System.currentTimeMillis() / 1000; long splitTime = System.currentTimeMillis() / 1000 - rsaValueInfo.getT();
if (splitTime > timeout) { if (splitTime > timeout && timeout > 0) {
throw new RuntimeCodeException("056", "解密超时"); throw new RuntimeCodeException("056", "解密超时");
} }
return rsaValueInfo.getV(); return rsaValueInfo.getV();
......
package helper; package helper;
import com.yanzuoguang.util.helper.RsaHelper; import com.yanzuoguang.util.helper.RsaHelper;
import com.yanzuoguang.util.thread.ThreadHelper;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
...@@ -42,10 +43,20 @@ public class TestRsa { ...@@ -42,10 +43,20 @@ public class TestRsa {
Assert.assertEquals(from, result); Assert.assertEquals(from, result);
String rsaTemp = RsaHelper.encodeRsaValueInfo(from, rsaInfo.getPublicKeyFrom()); String rsaTemp = RsaHelper.encodeRsaValueInfo(from, rsaInfo.getPublicKeyFrom());
String rsaResult = RsaHelper.decodeRsaValueInfo(rsaTemp, rsaInfo.getPrivateKeyFrom(), 10 * 1000); String rsaResult = RsaHelper.decodeRsaValueInfo(rsaTemp, rsaInfo.getPrivateKeyFrom(), 0);
System.out.println("Json时间公钥加密后字段:" + rsaTemp); System.out.println("Json时间公钥加密后字段:" + rsaTemp);
System.out.println("Json时间私钥解密后字段:" + rsaResult); System.out.println("Json时间私钥解密后字段:" + rsaResult);
Assert.assertEquals(from, rsaResult); Assert.assertEquals(from, rsaResult);
ThreadHelper.sleep(2000);
boolean isOk = false;
try {
String rsaResult1 = RsaHelper.decodeRsaValueInfo(rsaTemp, rsaInfo.getPrivateKeyFrom(), 1);
isOk = true;
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
Assert.assertFalse(isOk);
} }
...@@ -64,9 +75,19 @@ public class TestRsa { ...@@ -64,9 +75,19 @@ public class TestRsa {
Assert.assertEquals(from, result); Assert.assertEquals(from, result);
String rsaTemp = RsaHelper.encodeRsaValueInfo(from, rsaInfo.getPrivateKeyFrom()); String rsaTemp = RsaHelper.encodeRsaValueInfo(from, rsaInfo.getPrivateKeyFrom());
String rsaResult = RsaHelper.decodeRsaValueInfo(rsaTemp, rsaInfo.getPublicKeyFrom(), 10 * 1000); String rsaResult = RsaHelper.decodeRsaValueInfo(rsaTemp, rsaInfo.getPublicKeyFrom(), 0);
System.out.println("Json时间公钥加密后字段:" + rsaTemp); System.out.println("Json时间公钥加密后字段:" + rsaTemp);
System.out.println("Json时间私钥解密后字段:" + rsaResult); System.out.println("Json时间私钥解密后字段:" + rsaResult);
Assert.assertEquals(from, rsaResult); Assert.assertEquals(from, rsaResult);
ThreadHelper.sleep(2000);
boolean isOk = false;
try {
RsaHelper.decodeRsaValueInfo(rsaTemp, rsaInfo.getPublicKeyFrom(), 1);
isOk = true;
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
Assert.assertFalse(isOk);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment