Red Hat Application Migration Toolkit
package iaik.pkcs.pkcs7; import iaik.asn1.ASN1Object; import iaik.asn1.DerCoder; import iaik.asn1.DerInputStream; import iaik.asn1.INTEGER; import iaik.asn1.ObjectID; import iaik.asn1.SEQUENCE; import iaik.asn1.structures.AlgorithmID; import iaik.pkcs.PKCSException; import iaik.pkcs.PKCSParsingException; import iaik.pkcs.pkcs7.ContentStream; import iaik.pkcs.pkcs7.EncryptedContentInfoStream; import iaik.security.cipher.PBEKey; import iaik.security.cipher.PBEKeyBMP; import iaik.security.pbe.PBEGenParameterSpec; import iaik.utils.InternalErrorException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.security.AlgorithmParameterGenerator; import java.security.AlgorithmParameters; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.InvalidParameterSpecException; import javax.crypto.spec.PBEParameterSpec; public class EncryptedDataStream implements ContentStream { // $FF: synthetic field static Class b; private EncryptedContentInfoStream a; protected int block_size; protected int version; static Class a(String var0) { try { return Class.forName(var0); } catch (ClassNotFoundException var2) { throw new NoClassDefFoundError(var2.getMessage()); } } public void writeTo(OutputStream var1, int var2) throws IOException { try { DerCoder.encodeTo(this.toASN1Object(var2), var1); } catch (PKCSException var4) { throw new IOException(var4.toString()); } } public void writeTo(OutputStream var1) throws IOException { try { DerCoder.encodeTo(this.toASN1Object(), var1); } catch (PKCSException var3) { throw new IOException(var3.toString()); } } public String toString(boolean var1) { StringBuffer var2 = new StringBuffer(); var2.append("Version: " + this.version + "\n"); var2.append("EncryptedContentInfo:\n"); var2.append(this.a.toString()); return var2.toString(); } public String toString() { return this.toString(false); } protected ASN1Object toASN1Object(int var1) throws PKCSException { if(var1 <= 0) { var1 = this.block_size; } if(var1 > 0) { this.a.setBlockSize(var1); } SEQUENCE var2 = new SEQUENCE(true); var2.addComponent(new INTEGER(this.version)); var2.addComponent(this.a.toASN1Object()); return var2; } public ASN1Object toASN1Object() throws PKCSException { return this.toASN1Object(-1); } Key a(char[] var1, AlgorithmID var2) { return (Key)(var2.equals(AlgorithmID.pbeWithMD5AndDES_CBC)?new PBEKey(var1):new PBEKeyBMP(var1)); } public void setupCipher(char[] var1) throws InvalidKeyException, InvalidParameterSpecException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { AlgorithmID var2 = this.a.getContentEncryptionAlgorithm(); AlgorithmParameters var3 = var2.getAlgorithmParameters("PBE"); AlgorithmParameterSpec var4 = var3.getParameterSpec(b != null?b:(b = a("javax.crypto.spec.PBEParameterSpec"))); Key var5 = this.a(var1, this.a.getContentEncryptionAlgorithm()); this.a.setupCipher(var5, var4); } public void setupCipher(AlgorithmID var1, char[] var2, int var3) throws InvalidKeyException, NoSuchAlgorithmException { try { AlgorithmParameterSpec var4 = this.a(var1, var3); Key var5 = this.a(var2, var1); this.a.setupCipher(var1, var5, var4); } catch (InvalidAlgorithmParameterException var6) { throw new InternalErrorException(var6); } catch (InvalidParameterSpecException var7) { throw new InternalErrorException(var7); } } public void setupCipher(AlgorithmID var1, char[] var2) throws InvalidKeyException, NoSuchAlgorithmException { this.setupCipher(var1, var2, 1); } AlgorithmParameterSpec a(AlgorithmID var1, int var2) throws InvalidParameterSpecException, InvalidAlgorithmParameterException, NoSuchAlgorithmException { PBEGenParameterSpec var3 = new PBEGenParameterSpec(8, var2); AlgorithmParameterGenerator var4 = AlgorithmParameterGenerator.getInstance("PBE"); var4.init(var3); AlgorithmParameters var5 = var4.generateParameters(); PBEParameterSpec var6 = (PBEParameterSpec)var5.getParameterSpec(b != null?b:(b = a("javax.crypto.spec.PBEParameterSpec"))); var1.setAlgorithmParameters(var5); return var6; } public void setBlockSize(int var1) { this.block_size = var1; } public int getVersion() { return this.version; } public InputStream getInputStream() { return this.a.getInputStream(); } public Object getEncryptedContentInfo() { return this.a; } public ObjectID getContentType() { return ObjectID.pkcs7_encryptedData; } public int getBlockSize() { return this.block_size; } public void decode(InputStream var1) throws PKCSParsingException, IOException { if(!(var1 instanceof DerInputStream)) { var1 = new DerInputStream((InputStream)var1); } DerInputStream var2 = ((DerInputStream)var1).readSequence(); this.version = var2.readInteger().intValue(); this.a = new EncryptedContentInfoStream(var2); } public EncryptedDataStream(InputStream var1, int var2) { this(); this.a = new EncryptedContentInfoStream(ObjectID.pkcs7_data, var1); this.block_size = var2; } public EncryptedDataStream(InputStream var1) throws PKCSParsingException, IOException { this(); this.decode(var1); } public EncryptedDataStream(EncryptedContentInfoStream var1) { this(); this.a = var1; } protected EncryptedDataStream() { this.version = 0; this.block_size = -1; } }