1 22 package org.jboss.security.srp; 23 24 import java.io.Serializable ; 25 import java.util.Arrays ; 26 27 import org.jboss.security.Util; 28 29 36 public class SRPParameters implements Cloneable , Serializable 37 { 38 41 private static final long serialVersionUID = 6438772808805276693L; 42 43 44 public final byte[] N; 45 46 public final byte[] g; 47 48 public final byte[] s; 49 54 public final String hashAlgorithm; 55 57 public final String cipherAlgorithm; 58 60 public byte[] cipherIV; 61 62 63 public SRPParameters(byte[] N, byte[] g, byte[] s) 64 { 65 this(N, g, s, "SHA_Interleave", null); 66 } 67 public SRPParameters(byte[] N, byte[] g, byte[] s, String hashAlgorithm) 68 { 69 this(N, g, s, hashAlgorithm, null); 70 } 71 public SRPParameters(byte[] N, byte[] g, byte[] s, String hashAlgorithm, 72 String cipherAlgorithm) 73 { 74 this(N, g, s, hashAlgorithm, cipherAlgorithm, null); 75 } 76 public SRPParameters(byte[] N, byte[] g, byte[] s, String hashAlgorithm, 77 String cipherAlgorithm, byte[] cipherIV) 78 { 79 this.N = N; 80 this.g = g; 81 this.s = s; 82 if( hashAlgorithm == null ) 83 hashAlgorithm = "SHA_Interleave"; 84 this.hashAlgorithm = hashAlgorithm; 85 this.cipherAlgorithm = cipherAlgorithm; 86 this.cipherIV = cipherIV; 87 } 88 89 public Object clone() 90 { 91 Object clone = null; 92 try 93 { 94 clone = super.clone(); 95 } 96 catch(CloneNotSupportedException e) 97 { 98 } 99 return clone; 100 } 101 102 public int hashCode() 103 { 104 int hashCode = hashAlgorithm.hashCode(); 105 for(int i = 0; i < N.length; i ++) 106 hashCode += N[i]; 107 for(int i = 0; i < g.length; i ++) 108 hashCode += g[i]; 109 for(int i = 0; i < s.length; i ++) 110 hashCode += s[i]; 111 return hashCode; 112 } 113 114 public boolean equals(Object obj) 115 { 116 boolean equals = false; 117 if( obj instanceof SRPParameters ) 118 { 119 SRPParameters p = (SRPParameters) obj; 120 equals = hashAlgorithm.equals(p.hashAlgorithm); 121 if( equals == true ) 122 equals = Arrays.equals(N, p.N); 123 if( equals == true ) 124 equals = Arrays.equals(g, p.g); 125 if( equals == true ) 126 equals = Arrays.equals(s, p.s); 127 } 128 return equals; 129 } 130 131 public String toString() 132 { 133 StringBuffer tmp = new StringBuffer (super.toString()); 134 tmp.append('{'); 135 tmp.append("N: "); 136 tmp.append(Util.encodeBase64(N)); 137 tmp.append("|g: "); 138 tmp.append(Util.encodeBase64(g)); 139 tmp.append("|s: "); 140 tmp.append(Util.encodeBase64(s)); 141 tmp.append("|hashAlgorithm: "); 142 tmp.append(hashAlgorithm); 143 tmp.append("|cipherAlgorithm: "); 144 tmp.append(cipherAlgorithm); 145 tmp.append("|cipherIV: "); 146 tmp.append(cipherIV); 147 tmp.append('}'); 148 return tmp.toString(); 149 } 150 } 151 | Popular Tags |