1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.encrypt.openssl;
17
18 import static com.google.common.collect.Lists.newArrayList;
19 import static org.kuali.common.util.base.Precondition.checkNotNull;
20
21 import java.util.List;
22
23 import com.google.common.collect.ImmutableList;
24
25 public final class OpenSSLEncryptedContext {
26
27 private final ImmutableList<Byte> salt;
28 private final ImmutableList<Byte> key;
29 private final ImmutableList<Byte> initVector;
30
31 private OpenSSLEncryptedContext(Builder builder) {
32 this.salt = ImmutableList.copyOf(builder.salt);
33 this.key = ImmutableList.copyOf(builder.key);
34 this.initVector = ImmutableList.copyOf(builder.initVector);
35 }
36
37 public static Builder builder() {
38 return new Builder();
39 }
40
41 public static class Builder implements org.apache.commons.lang3.builder.Builder<OpenSSLEncryptedContext> {
42
43 private List<Byte> salt = newArrayList();
44 private List<Byte> key = newArrayList();
45 private List<Byte> initVector = newArrayList();
46
47 public Builder withSalt(List<Byte> salt) {
48 this.salt = salt;
49 return this;
50 }
51
52 public Builder withKey(List<Byte> key) {
53 this.key = key;
54 return this;
55 }
56
57 public Builder withInitVector(List<Byte> initVector) {
58 this.initVector = initVector;
59 return this;
60 }
61
62 @Override
63 public OpenSSLEncryptedContext build() {
64 return validate(new OpenSSLEncryptedContext(this));
65 }
66
67 private static OpenSSLEncryptedContext validate(OpenSSLEncryptedContext instance) {
68 checkNotNull(instance.salt, "salt");
69 checkNotNull(instance.key, "key");
70 checkNotNull(instance.initVector, "initVector");
71 return instance;
72 }
73
74 }
75
76 public List<Byte> getSalt() {
77 return salt;
78 }
79
80 public List<Byte> getKey() {
81 return key;
82 }
83
84 public List<Byte> getInitVector() {
85 return initVector;
86 }
87 }