mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 10:49:39 +02:00
Implement decryption with - and access of session keys
This commit is contained in:
parent
03f13ee4a7
commit
c55fd2e552
12 changed files with 334 additions and 37 deletions
|
@ -5,11 +5,15 @@
|
|||
package sop;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import sop.util.HexUtil;
|
||||
|
||||
public class SessionKey {
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile("^(\\d):([0-9a-fA-F]+)$");
|
||||
|
||||
private final byte algorithm;
|
||||
private final byte[] sessionKey;
|
||||
|
||||
|
@ -57,6 +61,17 @@ public class SessionKey {
|
|||
return getAlgorithm() == otherKey.getAlgorithm() && Arrays.equals(getKey(), otherKey.getKey());
|
||||
}
|
||||
|
||||
public static SessionKey fromString(String string) {
|
||||
Matcher matcher = PATTERN.matcher(string);
|
||||
if (!matcher.matches()) {
|
||||
throw new IllegalArgumentException("Provided session key does not match expected format.");
|
||||
}
|
||||
byte algorithm = Byte.parseByte(matcher.group(1));
|
||||
String key = matcher.group(2);
|
||||
|
||||
return new SessionKey(algorithm, HexUtil.hexToBytes(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "" + (int) getAlgorithm() + ':' + HexUtil.bytesToHex(sessionKey);
|
||||
|
|
|
@ -12,6 +12,13 @@ import sop.SessionKey;
|
|||
|
||||
public class SessionKeyTest {
|
||||
|
||||
@Test
|
||||
public void fromStringTest() {
|
||||
String string = "9:FCA4BEAF687F48059CACC14FB019125CD57392BAB7037C707835925CBF9F7BCD";
|
||||
SessionKey sessionKey = SessionKey.fromString(string);
|
||||
assertEquals(string, sessionKey.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
SessionKey sessionKey = new SessionKey((byte) 9, HexUtil.hexToBytes("FCA4BEAF687F48059CACC14FB019125CD57392BAB7037C707835925CBF9F7BCD"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue