bcpkix-jdk15on-147

tEncryptorBuilder$CMSOutputEncryptor
  implements OutputEncryptor
{
  private SecretKey encKey;
  private AlgorithmIdentifier algorithmIdentifier;
  private Cipher cipher;
  
  JceCMSContentEncryptorBuilder$CMSOutputEncryptor(JceCMSContentEncryptorBuilder paramJceCMSContentEncryptorBuilder, ASN1ObjectIdentifier paramASN1ObjectIdentifier, int paramInt, SecureRandom paramSecureRandom)
    throws CMSException
  {
    KeyGenerator localKeyGenerator = JceCMSContentEncryptorBuilder.access$000(paramJceCMSContentEncryptorBuilder).createKeyGenerator(paramASN1ObjectIdentifier);
    if (paramSecureRandom == null) {
      paramSecureRandom = new SecureRandom();
    }
    if (paramInt < 0) {
      localKeyGenerator.init(paramSecureRandom);
    } else {
      localKeyGenerator.init(paramInt, paramSecureRandom);
    }
    cipher = JceCMSContentEncryptorBuilder.access$000(paramJceCMSContentEncryptorBuilder).createCipher(paramASN1ObjectIdentifier);
    encKey = localKeyGenerator.generateKey();
    AlgorithmParameters localAlgorithmParameters = JceCMSContentEncryptorBuilder.access$000(paramJceCMSContentEncryptorBuilder).generateParameters(paramASN1ObjectIdentifier, encKey, paramSecureRandom);
    try
    {
      cipher.init(1, encKey, localAlgorithmParameters, paramSecureRandom);
    }
    catch (GeneralSecurityException localGeneralSecurityException)
    {
      throw new CMSException("unable to initialize cipher: " + localGeneralSecurityException.getMessage(), localGeneralSecurityException);
    }
    if (localAlgorithmParameters == null) {
      localAlgorithmParameters = cipher.getParameters();
    }
    algorithmIdentifier = JceCMSContentEncryptorBuilder.access$000(paramJceCMSContentEncryptorBuilder).getAlgorithmIdentifier(paramASN1ObjectIdentifier, localAlgorithmParameters);
  }
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return algorithmIdentifier;
  }
  
  public OutputStream getOutputStream(OutputStream paramOutputStream)
  {
    return new CipherOutputStream(paramOutputStream, cipher);
  }
  
  public GenericKey getKey()
  {
    return new GenericKey(encKey);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder.CMSOutputEncryptor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.OutputStream;
import java.security.AlgorithmParameters;
import java.security.GeneralSecurityException;
import java.security.Provider;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.CMSAlgorithm;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.OutputEncryptor;

public class JceCMSContentEncryptorBuilder
{
  private static Map keySizes = new HashMap();
  private final ASN1ObjectIdentifier encryptionOID;
  private final int keySize;
  private EnvelopedDataHelper helper = new EnvelopedDataHelper(new DefaultJcaJceExtHelper());
  private SecureRandom random;
  
  private static int getKeySize(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    Integer localInteger = (Integer)keySizes.get(paramASN1ObjectIdentifier);
    if (localInteger != null) {
      return localInteger.intValue();
    }
    return -1;
  }
  
  public JceCMSContentEncryptorBuilder(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    this(paramASN1ObjectIdentifier, getKeySize(paramASN1ObjectIdentifier));
  }
  
  public JceCMSContentEncryptorBuilder(ASN1ObjectIdentifier paramASN1ObjectIdentifier, int paramInt)
  {
    encryptionOID = paramASN1ObjectIdentifier;
    keySize = paramInt;
  }
  
  public JceCMSContentEncryptorBuilder setProvider(Provider paramProvider)
  {
    helper = new EnvelopedDataHelper(new ProviderJcaJceExtHelper(paramProvider));
    return this;
  }
  
  public JceCMSContentEncryptorBuilder setProvider(String paramString)
  {
    helper = new EnvelopedDataHelper(new NamedJcaJceExtHelper(paramString));
    return this;
  }
  
  public JceCMSContentEncryptorBuilder setSecureRandom(SecureRandom paramSecureRandom)
  {
    random = paramSecureRandom;
    return this;
  }
  
  public OutputEncryptor build()
    throws CMSException
  {
    return new CMSOutputEncryptor(encryptionOID, keySize, random);
  }
  
  static
  {
    keySizes.put(CMSAlgorithm.AES128_CBC, new Integer(128));
    keySizes.put(CMSAlgorithm.AES192_CBC, new Integer(192));
    keySizes.put(CMSAlgorithm.AES256_CBC, new Integer(256));
    keySizes.put(CMSAlgorithm.CAMELLIA128_CBC, new Integer(128));
    keySizes.put(CMSAlgorithm.CAMELLIA192_CBC, new Integer(192));
    keySizes.put(CMSAlgorithm.CAMELLIA256_CBC, new Integer(256));
  }
  
  private class CMSOutputEncryptor
    implements OutputEncryptor
  {
    private SecretKey encKey;
    private AlgorithmIdentifier algorithmIdentifier;
    private Cipher cipher;
    
    CMSOutputEncryptor(ASN1ObjectIdentifier paramASN1ObjectIdentifier, int paramInt, SecureRandom paramSecureRandom)
      throws CMSException
    {
      KeyGenerator localKeyGenerator = helper.createKeyGenerator(paramASN1ObjectIdentifier);
      if (paramSecureRandom == null) {
        paramSecureRandom = new SecureRandom();
      }
      if (paramInt < 0) {
        localKeyGenerator.init(paramSecureRandom);
      } else {
        localKeyGenerator.init(paramInt, paramSecureRandom);
      }
      cipher = helper.createCipher(paramASN1ObjectIdentifier);
      encKey = localKeyGenerator.generateKey();
      AlgorithmParameters localAlgorithmParameters = helper.generateParameters(paramASN1ObjectIdentifier, encKey, paramSecureRandom);
      try
      {
        cipher.init(1, encKey, localAlgorithmParameters, paramSecureRandom);
      }
      catch (GeneralSecurityException localGeneralSecurityException)
      {
        throw new CMSException("unable to initialize cipher: " + localGeneralSecurityException.getMessage(), localGeneralSecurityException);
      }
      if (localAlgorithmParameters == null) {
        localAlgorithmParameters = cipher.getParameters();
      }
      algorithmIdentifier = helper.getAlgorithmIdentifier(paramASN1ObjectIdentifier, localAlgorithmParameters);
    }
    
    public AlgorithmIdentifier getAlgorithmIdentifier()
    {
      return algorithmIdentifier;
    }
    
    public OutputStream getOutputStream(OutputStream paramOutputStream)
    {
      return new CipherOutputStream(paramOutputStream, cipher);
    }
    
    public GenericKey getKey()
    {
      return new GenericKey(encKey);
    }
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.OutputStream;
import java.security.AlgorithmParameterGenerator;
import java.security.AlgorithmParameters;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.RC2ParameterSpec;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.jcajce.io.MacOutputStream;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;

class JceCMSMacCalculatorBuilder$CMSOutputEncryptor
  implements MacCalculator
{
  private SecretKey encKey;
  private AlgorithmIdentifier algorithmIdentifier;
  private Mac mac;
  private SecureRandom random;
  
  JceCMSMacCalculatorBuilder$CMSOutputEncryptor(JceCMSMacCalculatorBuilder paramJceCMSMacCalculatorBuilder, ASN1ObjectIdentifier paramASN1ObjectIdentifier, int paramInt, SecureRandom paramSecureRandom)
    throws CMSException
  {
    KeyGenerator localKeyGenerator = JceCMSMacCalculatorBuilder.access$000(paramJceCMSMacCalculatorBuilder).createKeyGenerator(paramASN1ObjectIdentifier);
    if (paramSecureRandom == null) {
      paramSecureRandom = new SecureRandom();
    }
    random = paramSecureRandom;
    if (paramInt < 0) {
      localKeyGenerator.init(paramSecureRandom);
    } else {
      localKeyGenerator.init(paramInt, paramSecureRandom);
    }
    encKey = localKeyGenerator.generateKey();
    AlgorithmParameterSpec localAlgorithmParameterSpec = generateParameterSpec(paramASN1ObjectIdentifier, encKey);
    algorithmIdentifier = JceCMSMacCalculatorBuilder.access$000(paramJceCMSMacCalculatorBuilder).getAlgorithmIdentifier(paramASN1ObjectIdentifier, localAlgorithmParameterSpec);
    mac = JceCMSMacCalculatorBuilder.access$000(paramJceCMSMacCalculatorBuilder).createContentMac(encKey, algorithmIdentifier);
  }
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return algorithmIdentifier;
  }
  
  public OutputStream getOutputStream()
  {
    return new MacOutputStream(mac);
  }
  
  public byte[] getMac()
  {
    return mac.doFinal();
  }
  
  public GenericKey getKey()
  {
    return new GenericKey(encKey);
  }
  
  protected AlgorithmParameterSpec generateParameterSpec(ASN1ObjectIdentifier paramASN1ObjectIdentifier, SecretKey paramSecretKey)
    throws CMSException
  {
    try
    {
      if (paramASN1ObjectIdentifier.equals(PKCSObjectIdentifiers.RC2_CBC))
      {
        localObject = new byte[8];
        random.nextBytes((byte[])localObject);
        return new RC2ParameterSpec(paramSecretKey.getEncoded().length * 8, (byte[])localObject);
      }
      Object localObject = JceCMSMacCalculatorBuilder.access$000(this$0).createAlgorithmParameterGenerator(paramASN1ObjectIdentifier);
      AlgorithmParameters localAlgorithmParameters = ((AlgorithmParameterGenerator)localObject).generateParameters();
      return localAlgorithmParameters.getParameterSpec(IvParameterSpec.class);
    }
    catch (GeneralSecurityException localGeneralSecurityException) {}
    return null;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceCMSMacCalculatorBuilder.CMSOutputEncryptor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.OutputStream;
import java.security.AlgorithmParameterGenerator;
import java.security.AlgorithmParameters;
import java.security.GeneralSecurityException;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.RC2ParameterSpec;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.jcajce.io.MacOutputStream;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;

public class JceCMSMacCalculatorBuilder
{
  private final ASN1ObjectIdentifier macOID;
  private final int keySize;
  private EnvelopedDataHelper helper = new EnvelopedDataHelper(new DefaultJcaJceExtHelper());
  private SecureRandom random;
  private MacOutputStream macOutputStream;
  
  public JceCMSMacCalculatorBuilder(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    this(paramASN1ObjectIdentifier, -1);
  }
  
  public JceCMSMacCalculatorBuilder(ASN1ObjectIdentifier paramASN1ObjectIdentifier, int paramInt)
  {
    macOID = paramASN1ObjectIdentifier;
    keySize = paramInt;
  }
  
  public JceCMSMacCalculatorBuilder setProvider(Provider paramProvider)
  {
    helper = new EnvelopedDataHelper(new ProviderJcaJceExtHelper(paramProvider));
    return this;
  }
  
  public JceCMSMacCalculatorBuilder setProvider(String paramString)
  {
    helper = new EnvelopedDataHelper(new NamedJcaJceExtHelper(paramString));
    return this;
  }
  
  public JceCMSMacCalculatorBuilder setSecureRandom(SecureRandom paramSecureRandom)
  {
    random = paramSecureRandom;
    return this;
  }
  
  public MacCalculator build()
    throws CMSException
  {
    return new CMSOutputEncryptor(macOID, keySize, random);
  }
  
  private class CMSOutputEncryptor
    implements MacCalculator
  {
    private SecretKey encKey;
    private AlgorithmIdentifier algorithmIdentifier;
    private Mac mac;
    private SecureRandom random;
    
    CMSOutputEncryptor(ASN1ObjectIdentifier paramASN1ObjectIdentifier, int paramInt, SecureRandom paramSecureRandom)
      throws CMSException
    {
      KeyGenerator localKeyGenerator = helper.createKeyGenerator(paramASN1ObjectIdentifier);
      if (paramSecureRandom == null) {
        paramSecureRandom = new SecureRandom();
      }
      random = paramSecureRandom;
      if (paramInt < 0) {
        localKeyGenerator.init(paramSecureRandom);
      } else {
        localKeyGenerator.init(paramInt, paramSecureRandom);
      }
      encKey = localKeyGenerator.generateKey();
      AlgorithmParameterSpec localAlgorithmParameterSpec = generateParameterSpec(paramASN1ObjectIdentifier, encKey);
      algorithmIdentifier = helper.getAlgorithmIdentifier(paramASN1ObjectIdentifier, localAlgorithmParameterSpec);
      mac = helper.createContentMac(encKey, algorithmIdentifier);
    }
    
    public AlgorithmIdentifier getAlgorithmIdentifier()
    {
      return algorithmIdentifier;
    }
    
    public OutputStream getOutputStream()
    {
      return new MacOutputStream(mac);
    }
    
    public byte[] getMac()
    {
      return mac.doFinal();
    }
    
    public GenericKey getKey()
    {
      return new GenericKey(encKey);
    }
    
    protected AlgorithmParameterSpec generateParameterSpec(ASN1ObjectIdentifier paramASN1ObjectIdentifier, SecretKey paramSecretKey)
      throws CMSException
    {
      try
      {
        if (paramASN1ObjectIdentifier.equals(PKCSObjectIdentifiers.RC2_CBC))
        {
          localObject = new byte[8];
          random.nextBytes((byte[])localObject);
          return new RC2ParameterSpec(paramSecretKey.getEncoded().length * 8, (byte[])localObject);
        }
        Object localObject = helper.createAlgorithmParameterGenerator(paramASN1ObjectIdentifier);
        AlgorithmParameters localAlgorithmParameters = ((AlgorithmParameterGenerator)localObject).generateParameters();
        return localAlgorithmParameters.getParameterSpec(IvParameterSpec.class);
      }
      catch (GeneralSecurityException localGeneralSecurityException) {}
      return null;
    }
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceCMSMacCalculatorBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.OutputStream;
import java.security.Key;
import javax.crypto.Mac;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.jcajce.io.MacOutputStream;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;

class JceKEKAuthenticatedRecipient$1
  implements MacCalculator
{
  JceKEKAuthenticatedRecipient$1(JceKEKAuthenticatedRecipient paramJceKEKAuthenticatedRecipient, AlgorithmIdentifier paramAlgorithmIdentifier, Key paramKey, Mac paramMac) {}
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return val$contentMacAlgorithm;
  }
  
  public GenericKey getKey()
  {
    return new GenericKey(val$secretKey);
  }
  
  public OutputStream getOutputStream()
  {
    return new MacOutputStream(val$dataMac);
  }
  
  public byte[] getMac()
  {
    return val$dataMac.doFinal();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKEKAuthenticatedRecipient.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.OutputStream;
import java.security.Key;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.RecipientOperator;
import org.bouncycastle.jcajce.io.MacOutputStream;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;

public class JceKEKAuthenticatedRecipient
  extends JceKEKRecipient
{
  public JceKEKAuthenticatedRecipient(SecretKey paramSecretKey)
  {
    super(paramSecretKey);
  }
  
  public RecipientOperator getRecipientOperator(AlgorithmIdentifier paramAlgorithmIdentifier1, final AlgorithmIdentifier paramAlgorithmIdentifier2, byte[] paramArrayOfByte)
    throws CMSException
  {
    final Key localKey = extractSecretKey(paramAlgorithmIdentifier1, paramAlgorithmIdentifier2, paramArrayOfByte);
    final Mac localMac = contentHelper.createContentMac(localKey, paramAlgorithmIdentifier2);
    new RecipientOperator(new MacCalculator()
    {
      public AlgorithmIdentifier getAlgorithmIdentifier()
      {
        return paramAlgorithmIdentifier2;
      }
      
      public GenericKey getKey()
      {
        return new GenericKey(localKey);
      }
      
      public OutputStream getOutputStream()
      {
        return new MacOutputStream(localMac);
      }
      
      public byte[] getMac()
      {
        return localMac.doFinal();
      }
    });
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKEKAuthenticatedRecipient
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.InputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.operator.InputDecryptor;

class JceKEKEnvelopedRecipient$1
  implements InputDecryptor
{
  JceKEKEnvelopedRecipient$1(JceKEKEnvelopedRecipient paramJceKEKEnvelopedRecipient, AlgorithmIdentifier paramAlgorithmIdentifier, Cipher paramCipher) {}
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return val$contentEncryptionAlgorithm;
  }
  
  public InputStream getInputStream(InputStream paramInputStream)
  {
    return new CipherInputStream(paramInputStream, val$dataCipher);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKEKEnvelopedRecipient.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.InputStream;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.SecretKey;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.RecipientOperator;
import org.bouncycastle.operator.InputDecryptor;

public class JceKEKEnvelopedRecipient
  extends JceKEKRecipient
{
  public JceKEKEnvelopedRecipient(SecretKey paramSecretKey)
  {
    super(paramSecretKey);
  }
  
  public RecipientOperator getRecipientOperator(AlgorithmIdentifier paramAlgorithmIdentifier1, final AlgorithmIdentifier paramAlgorithmIdentifier2, byte[] paramArrayOfByte)
    throws CMSException
  {
    Key localKey = extractSecretKey(paramAlgorithmIdentifier1, paramAlgorithmIdentifier2, paramArrayOfByte);
    final Cipher localCipher = contentHelper.createContentCipher(localKey, paramAlgorithmIdentifier2);
    new RecipientOperator(new InputDecryptor()
    {
      public AlgorithmIdentifier getAlgorithmIdentifier()
      {
        return paramAlgorithmIdentifier2;
      }
      
      public InputStream getInputStream(InputStream paramAnonymousInputStream)
      {
        return new CipherInputStream(paramAnonymousInputStream, localCipher);
      }
    });
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKEKEnvelopedRecipient
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.security.Key;
import java.security.Provider;
import javax.crypto.SecretKey;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.KEKRecipient;
import org.bouncycastle.operator.OperatorException;
import org.bouncycastle.operator.SymmetricKeyUnwrapper;

public abstract class JceKEKRecipient
  implements KEKRecipient
{
  private SecretKey recipientKey;
  protected EnvelopedDataHelper helper = new EnvelopedDataHelper(new DefaultJcaJceExtHelper());
  protected EnvelopedDataHelper contentHelper = helper;
  
  public JceKEKRecipient(SecretKey paramSecretKey)
  {
    recipientKey = paramSecretKey;
  }
  
  public JceKEKRecipient setProvider(Provider paramProvider)
  {
    helper = new EnvelopedDataHelper(new ProviderJcaJceExtHelper(paramProvider));
    contentHelper = helper;
    return this;
  }
  
  public JceKEKRecipient setProvider(String paramString)
  {
    helper = new EnvelopedDataHelper(new NamedJcaJceExtHelper(paramString));
    contentHelper = helper;
    return this;
  }
  
  public JceKEKRecipient setContentProvider(Provider paramProvider)
  {
    contentHelper = new EnvelopedDataHelper(new ProviderJcaJceExtHelper(paramProvider));
    return this;
  }
  
  public JceKEKRecipient setContentProvider(String paramString)
  {
    contentHelper = new EnvelopedDataHelper(new NamedJcaJceExtHelper(paramString));
    return this;
  }
  
  protected Key extractSecretKey(AlgorithmIdentifier paramAlgorithmIdentifier1, AlgorithmIdentifier paramAlgorithmIdentifier2, byte[] paramArrayOfByte)
    throws CMSException
  {
    SymmetricKeyUnwrapper localSymmetricKeyUnwrapper = helper.createSymmetricUnwrapper(paramAlgorithmIdentifier1, recipientKey);
    try
    {
      return helper.getJceKey(paramAlgorithmIdentifier2.getAlgorithm(), localSymmetricKeyUnwrapper.generateUnwrappedKey(paramAlgorithmIdentifier2, paramArrayOfByte));
    }
    catch (OperatorException localOperatorException)
    {
      throw new CMSException("exception unwrapping key: " + localOperatorException.getMessage(), localOperatorException);
    }
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKEKRecipient
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.security.Provider;
import java.security.SecureRandom;
import javax.crypto.SecretKey;
import org.bouncycastle.asn1.cms.KEKIdentifier;
import org.bouncycastle.cms.KEKRecipientInfoGenerator;
import org.bouncycastle.operator.jcajce.JceSymmetricKeyWrapper;

public class JceKEKRecipientInfoGenerator
  extends KEKRecipientInfoGenerator
{
  public JceKEKRecipientInfoGenerator(KEKIdentifier paramKEKIdentifier, SecretKey paramSecretKey)
  {
    super(paramKEKIdentifier, new JceSymmetricKeyWrapper(paramSecretKey));
  }
  
  public JceKEKRecipientInfoGenerator(byte[] paramArrayOfByte, SecretKey paramSecretKey)
  {
    this(new KEKIdentifier(paramArrayOfByte, null, null), paramSecretKey);
  }
  
  public JceKEKRecipientInfoGenerator setProvider(Provider paramProvider)
  {
    ((JceSymmetricKeyWrapper)wrapper).setProvider(paramProvider);
    return this;
  }
  
  public JceKEKRecipientInfoGenerator setProvider(String paramString)
  {
    ((JceSymmetricKeyWrapper)wrapper).setProvider(paramString);
    return this;
  }
  
  public JceKEKRecipientInfoGenerator setSecureRandom(SecureRandom paramSecureRandom)
  {
    ((JceSymmetricKeyWrapper)wrapper).setSecureRandom(paramSecureRandom);
    return this;
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKEKRecipientInfoGenerator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.OutputStream;
import java.security.Key;
import javax.crypto.Mac;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.jcajce.io.MacOutputStream;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;

class JceKeyAgreeAuthenticatedRecipient$1
  implements MacCalculator
{
  JceKeyAgreeAuthenticatedRecipient$1(JceKeyAgreeAuthenticatedRecipient paramJceKeyAgreeAuthenticatedRecipient, AlgorithmIdentifier paramAlgorithmIdentifier, Key paramKey, Mac paramMac) {}
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return val$contentMacAlgorithm;
  }
  
  public GenericKey getKey()
  {
    return new GenericKey(val$secretKey);
  }
  
  public OutputStream getOutputStream()
  {
    return new MacOutputStream(val$dataMac);
  }
  
  public byte[] getMac()
  {
    return val$dataMac.doFinal();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKeyAgreeAuthenticatedRecipient.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.OutputStream;
import java.security.Key;
import java.security.PrivateKey;
import javax.crypto.Mac;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.RecipientOperator;
import org.bouncycastle.jcajce.io.MacOutputStream;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.MacCalculator;

public class JceKeyAgreeAuthenticatedRecipient
  extends JceKeyAgreeRecipient
{
  public JceKeyAgreeAuthenticatedRecipient(PrivateKey paramPrivateKey)
  {
    super(paramPrivateKey);
  }
  
  public RecipientOperator getRecipientOperator(AlgorithmIdentifier paramAlgorithmIdentifier1, final AlgorithmIdentifier paramAlgorithmIdentifier2, SubjectPublicKeyInfo paramSubjectPublicKeyInfo, ASN1OctetString paramASN1OctetString, byte[] paramArrayOfByte)
    throws CMSException
  {
    final Key localKey = extractSecretKey(paramAlgorithmIdentifier1, paramAlgorithmIdentifier2, paramSubjectPublicKeyInfo, paramASN1OctetString, paramArrayOfByte);
    final Mac localMac = contentHelper.createContentMac(localKey, paramAlgorithmIdentifier2);
    new RecipientOperator(new MacCalculator()
    {
      public AlgorithmIdentifier getAlgorithmIdentifier()
      {
        return paramAlgorithmIdentifier2;
      }
      
      public GenericKey getKey()
      {
        return new GenericKey(localKey);
      }
      
      public OutputStream getOutputStream()
      {
        return new MacOutputStream(localMac);
      }
      
      public byte[] getMac()
      {
        return localMac.doFinal();
      }
    });
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKeyAgreeAuthenticatedRecipient
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.InputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.operator.InputDecryptor;

class JceKeyAgreeEnvelopedRecipient$1
  implements InputDecryptor
{
  JceKeyAgreeEnvelopedRecipient$1(JceKeyAgreeEnvelopedRecipient paramJceKeyAgreeEnvelopedRecipient, AlgorithmIdentifier paramAlgorithmIdentifier, Cipher paramCipher) {}
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return val$contentEncryptionAlgorithm;
  }
  
  public InputStream getInputStream(InputStream paramInputStream)
  {
    return new CipherInputStream(paramInputStream, val$dataCipher);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKeyAgreeEnvelopedRecipient.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.InputStream;
import java.security.Key;
import java.security.PrivateKey;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.RecipientOperator;
import org.bouncycastle.operator.InputDecryptor;

public class JceKeyAgreeEnvelopedRecipient
  extends JceKeyAgreeRecipient
{
  public JceKeyAgreeEnvelopedRecipient(PrivateKey paramPrivateKey)
  {
    super(paramPrivateKey);
  }
  
  public RecipientOperator getRecipientOperator(AlgorithmIdentifier paramAlgorithmIdentifier1, final AlgorithmIdentifier paramAlgorithmIdentifier2, SubjectPublicKeyInfo paramSubjectPublicKeyInfo, ASN1OctetString paramASN1OctetString, byte[] paramArrayOfByte)
    throws CMSException
  {
    Key localKey = extractSecretKey(paramAlgorithmIdentifier1, paramAlgorithmIdentifier2, paramSubjectPublicKeyInfo, paramASN1OctetString, paramArrayOfByte);
    final Cipher localCipher = contentHelper.createContentCipher(localKey, paramAlgorithmIdentifier2);
    new RecipientOperator(new InputDecryptor()
    {
      public AlgorithmIdentifier getAlgorithmIdentifier()
      {
        return paramAlgorithmIdentifier2;
      }
      
      public InputStream getInputStream(InputStream paramAnonymousInputStream)
      {
        return new CipherInputStream(paramAnonymousInputStream, localCipher);
      }
    });
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKeyAgreeEnvelopedRecipient
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.Cipher;
import javax.crypto.KeyAgreement;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.DERBitString;
import org.bouncycastle.asn1.cms.OriginatorPublicKey;
import org.bouncycastle.asn1.cms.ecc.MQVuserKeyingMaterial;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cms.CMSEnvelopedGenerator;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.KeyAgreeRecipient;
import org.bouncycastle.jce.spec.MQVPrivateKeySpec;
import org.bouncycastle.jce.spec.MQVPublicKeySpec;

public abstract class JceKeyAgreeRecipient
  implements KeyAgreeRecipient
{
  private PrivateKey recipientKey;
  protected EnvelopedDataHelper helper = new EnvelopedDataHelper(new DefaultJcaJceExtHelper());
  protected EnvelopedDataHelper contentHelper = helper;
  
  public JceKeyAgreeRecipient(PrivateKey paramPrivateKey)
  {
    recipientKey = paramPrivateKey;
  }
  
  public JceKeyAgreeRecipient setProvider(Provider paramProvider)
  {
    helper = new EnvelopedDataHelper(new ProviderJcaJceExtHelper(paramProvider));
    contentHelper = helper;
    return this;
  }
  
  public JceKeyAgreeRecipient setProvider(String paramString)
  {
    helper = new EnvelopedDataHelper(new NamedJcaJceExtHelper(paramString));
    contentHelper = helper;
    return this;
  }
  
  public JceKeyAgreeRecipient setContentProvider(Provider paramProvider)
  {
    contentHelper = CMSUtils.createContentHelper(paramProvider);
    return this;
  }
  
  public JceKeyAgreeRecipient setContentProvider(String paramString)
  {
    contentHelper = CMSUtils.createContentHelper(paramString);
    return this;
  }
  
  private SecretKey calculateAgreedWrapKey(AlgorithmIdentifier paramAlgorithmIdentifier, ASN1ObjectIdentifier paramASN1ObjectIdentifier, PublicKey paramPublicKey, ASN1OctetString paramASN1OctetString, PrivateKey paramPrivateKey)
    throws CMSException, GeneralSecurityException, IOException
  {
    String str = paramAlgorithmIdentifier.getAlgorithm().getId();
    if (str.equals(CMSEnvelopedGenerator.ECMQV_SHA1KDF))
    {
      localObject = paramASN1OctetString.getOctets();
      MQVuserKeyingMaterial localMQVuserKeyingMaterial = MQVuserKeyingMaterial.getInstance(ASN1Primitive.fromByteArray((byte[])localObject));
      SubjectPublicKeyInfo localSubjectPublicKeyInfo = new SubjectPublicKeyInfo(getPrivateKeyAlgorithmIdentifier(), localMQVuserKeyingMaterial.getEphemeralPublicKey().getPublicKey().getBytes());
      X509EncodedKeySpec localX509EncodedKeySpec = new X509EncodedKeySpec(localSubjectPublicKeyInfo.getEncoded());
      KeyFactory localKeyFactory = helper.createKeyFactory(paramAlgorithmIdentifier.getAlgorithm());
      PublicKey localPublicKey = localKeyFactory.generatePublic(localX509EncodedKeySpec);
      paramPublicKey = new MQVPublicKeySpec(paramPublicKey, localPublicKey);
      paramPrivateKey = new MQVPrivateKeySpec(paramPrivateKey, paramPrivateKey);
    }
    Object localObject = helper.createKeyAgreement(paramAlgorithmIdentifier.getAlgorithm());
    ((KeyAgreement)localObject).init(paramPrivateKey);
    ((KeyAgreement)localObject).doPhase(paramPublicKey, true);
    return ((KeyAgreement)localObject).generateSecret(paramASN1ObjectIdentifier.getId());
  }
  
  private Key unwrapSessionKey(ASN1ObjectIdentifier paramASN1ObjectIdentifier1, SecretKey paramSecretKey, ASN1ObjectIdentifier paramASN1ObjectIdentifier2, byte[] paramArrayOfByte)
    throws CMSException, InvalidKeyException, NoSuchAlgorithmException
  {
    Cipher localCipher = helper.createCipher(paramASN1ObjectIdentifier1);
    localCipher.init(4, paramSecretKey);
    return localCipher.unwrap(paramArrayOfByte, helper.getBaseCipherName(paramASN1ObjectIdentifier2), 3);
  }
  
  protected Key extractSecretKey(AlgorithmIdentifier paramAlgorithmIdentifier1, AlgorithmIdentifier paramAlgorithmIdentifier2, SubjectPublicKeyInfo paramSubjectPublicKeyInfo, ASN1OctetString paramASN1OctetString, byte[] paramArrayOfByte)
    throws CMSException
  {
    try
    {
      ASN1ObjectIdentifier localASN1ObjectIdentifier = AlgorithmIdentifier.getInstance(paramAlgorithmIdentifier1.getParameters()).getAlgorithm();
      X509EncodedKeySpec localX509EncodedKeySpec = new X509EncodedKeySpec(paramSubjectPublicKeyInfo.getEncoded());
      KeyFactory localKeyFactory = helper.createKeyFactory(paramAlgorithmIdentifier1.getAlgorithm());
      PublicKey localPublicKey = localKeyFactory.generatePublic(localX509EncodedKeySpec);
      SecretKey localSecretKey = calculateAgreedWrapKey(paramAlgorithmIdentifier1, localASN1ObjectIdentifier, localPublicKey, paramASN1OctetString, recipientKey);
      return unwrapSessionKey(localASN1ObjectIdentifier, localSecretKey, paramAlgorithmIdentifier2.getAlgorithm(), paramArrayOfByte);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new CMSException("can't find algorithm.", localNoSuchAlgorithmException);
    }
    catch (InvalidKeyException localInvalidKeyException)
    {
      throw new CMSException("key invalid in message.", localInvalidKeyException);
    }
    catch (InvalidKeySpecException localInvalidKeySpecException)
    {
      throw new CMSException("originator key spec invalid.", localInvalidKeySpecException);
    }
    catch (NoSuchPaddingException localNoSuchPaddingException)
    {
      throw new CMSException("required padding not supported.", localNoSuchPaddingException);
    }
    catch (Exception localException)
    {
      throw new CMSException("originator key invalid.", localException);
    }
  }
  
  public AlgorithmIdentifier getPrivateKeyAlgorithmIdentifier()
  {
    return PrivateKeyInfo.getInstance(recipientKey.getEncoded()).getAlgorithmId();
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKeyAgreeRecipient
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.math.BigInteger;
import java.security.cert.X509Certificate;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.cms.KeyAgreeRecipientId;

public class JceKeyAgreeRecipientId
  extends KeyAgreeRecipientId
{
  public JceKeyAgreeRecipientId(X509Certificate paramX509Certificate)
  {
    this(paramX509Certificate.getIssuerX500Principal(), paramX509Certificate.getSerialNumber());
  }
  
  public JceKeyAgreeRecipientId(X500Principal paramX500Principal, BigInteger paramBigInteger)
  {
    super(X500Name.getInstance(paramX500Principal.getEncoded()), paramBigInteger);
  }
}

/* Location:
 * Qualified Name:     org.bouncycastle.cms.jcajce.JceKeyAgreeRecipientId
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.bouncycastle.cms.jcajce;

import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.security.interfaces.ECPublicKey;
import java.security.spec.ECParameterSpec;
import java.util.ArrayList;
import java.util.List;
import javax.crypto.Cipher;
import javax.crypto.KeyAgreement;
import javax.crypto.SecretKey;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.cms.KeyAgreeRecipientIdentifier;
import org.bouncycastle.asn1.cms.RecipientEncryptedKey;
import org.bouncycastle.asn1.cms.RecipientKeyIdentifier;
import org.bouncycastle.asn1.cms.ecc.MQVuserKeyingMaterial;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.cms.CMSAlgorithm;
import org.bouncycastle.cms.CMSEnvelopedGenerator;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.KeyAgreeRecipientInfoGenerator;
import org.bouncycastle.jce.spec.MQVPrivateKeySpec;
import org.bouncycastle.jce.spec.MQVPublicKeySpec;
import org.bouncycastle.operator.GenericKey;

public class JceKeyAgreeRecipientInfoGenerator
  extends KeyAgreeRecipientInfoGenerator
{
  private List recipientIDs = new ArrayList();
  private List recipientKeys = new ArrayList();
  private PublicKey senderPublicKey;
  private PrivateKey senderPrivateKey;
  private EnvelopedDataHelper helper = new EnvelopedDataHelper(new DefaultJcaJceExtHelper());
  private SecureRandom random;
  private KeyPair ephemeralKP;
  
  public JceKeyAgreeRecipientInfoGenerator(ASN1ObjectIdentifier paramASN1ObjectIdentifier1, PrivateKey paramPrivateKey, PublicKey paramPublicKey, ASN1ObjectIdentifier paramASN1ObjectIdentifier2)
  {
    super(paramASN1ObjectIdentifier1, SubjectPublicKeyInfo.getInstance(paramPublicKey.getEncoded()), paramASN1ObjectIdentifier2);
    senderPublicKey = paramPublicKey;
    senderPrivateKey = paramPrivateKey;
  }
  
  public JceKeyAgreeRecipientInfoGenerator setProvider(Provider paramProvider)
  {
    helper = new EnvelopedDataHelper(new ProviderJcaJceExtHelper(paramProvider));
    return this;
  }
  
  public JceKeyAgreeRecipientInfoGenerator setProvider(String paramString)
  {
    helper = new EnvelopedDataHelper(new NamedJcaJceExtHelper(paramString));
    return this;
  }
  
  public JceKeyAgreeRecipientInfoGenerator setSecureRandom(SecureRandom paramSecureRandom)
  {
    random = paramSecureRandom;
    return this;
  }
  
  public JceKeyAgreeRecipientInfoGenerator add
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd