1 20 package com.novosec.pkix.asn1.crmf; 21 22 import java.util.Enumeration ; 23 24 import org.bouncycastle.asn1.ASN1EncodableVector; 25 import org.bouncycastle.asn1.ASN1Sequence; 26 import org.bouncycastle.asn1.ASN1TaggedObject; 27 import org.bouncycastle.asn1.DERBitString; 28 import org.bouncycastle.asn1.DEREncodable; 29 import org.bouncycastle.asn1.DERObject; 30 import org.bouncycastle.asn1.DEROctetString; 31 import org.bouncycastle.asn1.DERSequence; 32 import org.bouncycastle.asn1.DERTaggedObject; 33 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 34 35 49 50 public class EncryptedValue implements DEREncodable 51 { 52 AlgorithmIdentifier intendedAlg; 53 AlgorithmIdentifier symmAlg; 54 DERBitString encSymmKey; 55 AlgorithmIdentifier keyAlg; 56 DEROctetString valueHint; 57 DERBitString encValue; 58 59 public static EncryptedValue getInstance( ASN1TaggedObject obj, boolean explicit ) 60 { 61 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 62 } 63 64 public static EncryptedValue getInstance( Object obj ) 65 { 66 if (obj instanceof EncryptedValue) 67 { 68 return (EncryptedValue)obj; 69 } 70 else if (obj instanceof ASN1Sequence) 71 { 72 return new EncryptedValue((ASN1Sequence)obj); 73 } 74 75 throw new IllegalArgumentException ("unknown object in factory"); 76 } 77 78 public EncryptedValue( ASN1Sequence seq ) 79 { 80 Enumeration e = seq.getObjects(); 81 while (e.hasMoreElements()) 82 { 83 Object obj = e.nextElement(); 84 85 if( obj instanceof DERTaggedObject ) 86 { 87 DERTaggedObject tagObj = (DERTaggedObject)obj; 88 89 switch( tagObj.getTagNo() ) 90 { 91 case 0: this.intendedAlg = AlgorithmIdentifier.getInstance( tagObj.getObject() ); break; 92 case 1: this.symmAlg = AlgorithmIdentifier.getInstance( tagObj.getObject() ); break; 93 case 2: this.encSymmKey = DERBitString.getInstance( tagObj.getObject() ); break; 94 case 3: this.keyAlg = AlgorithmIdentifier.getInstance( tagObj.getObject() ); break; 95 case 4: this.valueHint = (DEROctetString)DEROctetString.getInstance( tagObj.getObject() ); break; 96 } 97 } 98 else 99 { 100 encValue = DERBitString.getInstance( obj ); 101 break; 102 } 103 } 104 } 105 106 public EncryptedValue(DERBitString encValue) 107 { 108 this.encValue = encValue; 109 } 110 111 public AlgorithmIdentifier getIntendedAlg() 112 { 113 return intendedAlg; 114 } 115 116 public void setIntendedAlg(AlgorithmIdentifier intendedAlg) 117 { 118 this.intendedAlg = intendedAlg; 119 } 120 121 public AlgorithmIdentifier getSymmAlg() 122 { 123 return symmAlg; 124 } 125 126 public void setSymmAlg(AlgorithmIdentifier symmAlg) 127 { 128 this.symmAlg = symmAlg; 129 } 130 131 public DERBitString getEncSymmKey() 132 { 133 return encSymmKey; 134 } 135 136 public void setEncSymmKey(DERBitString encSymmKey) 137 { 138 this.encSymmKey = encSymmKey; 139 } 140 141 public AlgorithmIdentifier getKeyAlg() 142 { 143 return keyAlg; 144 } 145 146 public void setKeyAlg(AlgorithmIdentifier keyAlg) 147 { 148 this.keyAlg = keyAlg; 149 } 150 151 public DEROctetString getValueHint() 152 { 153 return valueHint; 154 } 155 156 public void setValueHint(DEROctetString valueHint) 157 { 158 this.valueHint = valueHint; 159 } 160 161 public DERBitString getEncValue() 162 { 163 return encValue; 164 } 165 166 public DERObject getDERObject() 167 { 168 ASN1EncodableVector v = new ASN1EncodableVector(); 169 170 if( intendedAlg != null ) 171 v.add( new DERTaggedObject( false, 0, intendedAlg ) ); 172 if( symmAlg != null ) 173 v.add( new DERTaggedObject( false, 1, symmAlg ) ); 174 if( encSymmKey != null ) 175 v.add( new DERTaggedObject( false, 2, encSymmKey ) ); 176 if( keyAlg != null ) 177 v.add( new DERTaggedObject( false, 3, keyAlg ) ); 178 if( valueHint != null ) 179 v.add( new DERTaggedObject( false, 4, valueHint ) ); 180 181 v.add( encValue ); 182 183 return new DERSequence(v); 184 } 185 186 public String toString() 187 { 188 String s = "EncryptedValue: ("; 189 190 if( this.getIntendedAlg() != null ) 191 s += "intendedAlg: " + this.getIntendedAlg() + ", "; 192 193 if( this.getSymmAlg() != null ) 194 s += "symmAlg: " + this.getSymmAlg() + ", "; 195 196 if( this.getEncSymmKey() != null ) 197 s += "encSymmKey: " + this.getEncSymmKey() + ", "; 198 199 if( this.getKeyAlg() != null ) 200 s += "keyAlg: " + this.getKeyAlg() + ", "; 201 202 if( this.getValueHint() != null ) 203 s += "valueHint: " + this.getValueHint() + ", "; 204 205 s += "encValue: " + this.getEncValue() + ")"; 206 207 return s; 208 } 209 } 210 | Popular Tags |