diff --git a/src/main/java/io/twentysixty/sa/client/model/message/Ciphering.java b/src/main/java/io/twentysixty/sa/client/model/message/Ciphering.java index 8996835..3d68e35 100644 --- a/src/main/java/io/twentysixty/sa/client/model/message/Ciphering.java +++ b/src/main/java/io/twentysixty/sa/client/model/message/Ciphering.java @@ -1,31 +1,16 @@ package io.twentysixty.sa.client.model.message; import java.io.Serializable; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +@Setter +@Getter +@ToString public class Ciphering implements Serializable { private static final long serialVersionUID = -8660299956191649637L; private String algorithm; private Parameters parameters; - - public String getAlgorithm() { - return algorithm; - } - - public void setAlgorithm(String algorithm) { - this.algorithm = algorithm; - } - - public Parameters getParameters() { - return parameters; - } - - public void setParameters(Parameters parameters) { - this.parameters = parameters; - } - - @Override - public String toString() { - return "Ciphering [algorithm=" + algorithm + ", parameters=" + parameters + "]"; - } } diff --git a/src/main/java/io/twentysixty/sa/client/model/message/Parameters.java b/src/main/java/io/twentysixty/sa/client/model/message/Parameters.java index a053af0..86e83d4 100644 --- a/src/main/java/io/twentysixty/sa/client/model/message/Parameters.java +++ b/src/main/java/io/twentysixty/sa/client/model/message/Parameters.java @@ -1,31 +1,16 @@ package io.twentysixty.sa.client.model.message; import java.io.Serializable; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +@Setter +@Getter +@ToString public class Parameters implements Serializable { private static final long serialVersionUID = -3591319454008944749L; private String key; private String iv; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getIv() { - return iv; - } - - public void setIv(String iv) { - this.iv = iv; - } - - @Override - public String toString() { - return "Parameters [key=" + key + ", iv=" + iv + "]"; - } } diff --git a/src/main/java/io/twentysixty/sa/client/util/Aes256cbc.java b/src/main/java/io/twentysixty/sa/client/util/Aes256cbc.java index 65502f2..e4ad753 100644 --- a/src/main/java/io/twentysixty/sa/client/util/Aes256cbc.java +++ b/src/main/java/io/twentysixty/sa/client/util/Aes256cbc.java @@ -1,6 +1,10 @@ package io.twentysixty.sa.client.util; +import io.twentysixty.sa.client.model.message.Ciphering; +import io.twentysixty.sa.client.model.message.Parameters; import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import org.jboss.logging.Logger; @@ -40,4 +44,21 @@ public static byte[] decrypt(String key, String iv, byte[] encrypted) throws Exc byte[] decrypted = cipher.doFinal(encrypted); return decrypted; } + + public static Ciphering randomCipheringData() throws Exception { + Ciphering c = new Ciphering(); + Parameters p = new Parameters(); + p.setKey(randomKey(32)); + p.setIv(randomKey(16)); + c.setAlgorithm(cI); + c.setParameters(p); + return c; + } + + private static String randomKey(int size) throws Exception { + KeyGenerator keyGen = KeyGenerator.getInstance(alg); + keyGen.init(size * 8); + SecretKey secretKey = keyGen.generateKey(); + return ISOUtil.dumpString(secretKey.getEncoded()); + } }