bcpkix-jdk15on-147

ycastle.operator.RawContentVerifier;
import org.bouncycastle.operator.RuntimeOperatorException;

public class JcaContentVerifierProviderBuilder
{
  private OperatorHelper helper = new OperatorHelper(new DefaultJcaJceHelper());
  
  public JcaContentVerifierProviderBuilder setProvider(Provider paramProvider)
  {
    helper = new OperatorHelper(new ProviderJcaJceHelper(paramProvider));
    return this;
  }
  
  public JcaContentVerifierProviderBuilder setProvider(String paramString)
  {
    helper = new OperatorHelper(new NamedJcaJceHelper(paramString));
    return this;
  }
  
  public ContentVerifierProvider build(X509CertificateHolder paramX509CertificateHolder)
    throws OperatorCreationException, CertificateException
  {
    return build(helper.convertCertificate(paramX509CertificateHolder));
  }
  
  public ContentVerifierProvider build(final X509Certificate paramX509Certificate)
    throws OperatorCreationException
  {
    final JcaX509CertificateHolder localJcaX509CertificateHolder;
    try
    {
      localJcaX509CertificateHolder = new JcaX509CertificateHolder(paramX509Certificate);
    }
    catch (CertificateEncodingException localCertificateEncodingException)
    {
      throw new OperatorCreationException("cannot process certificate: " + localCertificateEncodingException.getMessage(), localCertificateEncodingException);
    }
    new ContentVerifierProvider()
    {
      private JcaContentVerifierProviderBuilder.SignatureOutputStream stream;
      
      public boolean hasAssociatedCertificate()
      {
        return true;
      }
      
      public X509CertificateHolder getAssociatedCertificate()
      {
        return localJcaX509CertificateHolder;
      }
      
      public ContentVerifier get(AlgorithmIdentifier paramAnonymousAlgorithmIdentifier)
        throws OperatorCreationException
      {
        try
        {
          Signature localSignature1 = helper.createSignature(paramAnonymousAlgorithmIdentifier);
          localSignature1.initVerify(paramX509Certificate.getPublicKey());
          stream = new JcaContentVerifierProviderBuilder.SignatureOutputStream(JcaContentVerifierProviderBuilder.this, localSignature1);
        }
        catch (GeneralSecurityException localGeneralSecurityException)
        {
          throw new OperatorCreationException("exception on setup: " + localGeneralSecurityException, localGeneralSecurityException);
        }
        Signature localSignature2 = JcaContentVerifierProviderBuilder.this.createRawSig(paramAnonymousAlgorithmIdentifier, paramX509Certificate.getPublicKey());
        if (localSignature2 != null) {
          return new JcaContentVerifierProviderBuilder.RawSigVerifier(JcaContentVerifierProviderBuilder.this, paramAnonymousAlgorithmIdentifier, stream, localSignature2);
        }
        return new JcaContentVerifierProviderBuilder.SigVerifier(JcaContentVerifierProviderBuilder.this, paramAnonymousAlgorithmIdentifier, stream);
      }
    };
  }
  
  public ContentVerifierProvider build(final PublicKey paramPublicKey)
    throws OperatorCreationException
  {
    new ContentVerifierProvider()
    {
      public boolean hasAssociatedCertificate()
      {
        return false;
      }
      
      public X509CertificateHolder getAssociatedCertificate()
      {
        return null;
      }
      
      public ContentVerifier get(AlgorithmIdentifier paramAnonymousAlgorithmIdentifier)
        throws OperatorCreationException
      {
        JcaContentVerifierProviderBuilder.SignatureOutputStream localSignatureOutputStream = JcaContentVerifierProviderBuilder.this.createSignatureStream(paramAnonymousAlgorithmIdentifier, paramPublicKey);
        Signature localSignature = JcaContentVerifierProviderBuilder.this.createRawSig(paramAnonymousAlgorithmIdentifier, paramPublicKey);
        if (localSignature != null) {
          return new JcaContentVerifierProviderBuilder.RawSigVerifier(JcaContentVerifierProviderBuilder.this, paramAnonymousAlgorithmIdentifier, localSignatureOutputStream, localSignature);
        }
        return new JcaContentVerifierProviderBuilder.SigVerifier(JcaContentVerifierProviderBuilder.this, paramAnonymousAlgorithmIdentifier, localSignatureOutputStream);
      }
    };
  }
  
  private SignatureOutputStream createSignatureStream(AlgorithmIdentifier paramAlgorithmIdentifier, PublicKey paramPublicKey)
    throws OperatorCreationException
  {
    try
    {
      Signature localSignature = helper.createSignature(paramAlgorithmIdentifier);
      localSignature.initVerify(paramPublicKey);
      return new SignatureOutputStream(localSignature);
    }
    catch (GeneralSecurityException localGeneralSecurityException)
    {
      throw new OperatorCreationException("exception on setup: " + localGeneralSecurityException, localGeneralSecurityException);
    }
  }
  
  private Signature createRawSig(AlgorithmIdentifier paramAlgorithmIdentifier, PublicKey paramPublicKey)
  {
    Signature localSignature;
    try
    {
      localSignature = helper.createRawSignature(paramAlgorithmIdentifier);
      if (localSignature != null) {
        localSignature.initVerify(paramPublicKey);
      }
    }
    catch (Exception localException)
    {
      localSignature = null;
    }
    return localSignature;
  }
  
  private class RawSigVerifier
    extends JcaContentVerifierProviderBuilder.SigVerifier
    implements RawContentVerifier
  {
    private Signature rawSignature;
    
    RawSigVerifier(AlgorithmIdentifier paramAlgorithmIdentifier, JcaContentVerifierProviderBuilder.SignatureOutputStream paramSignatureOutputStream, Signature paramSignature)
    {
      super(paramAlgorithmIdentifier, paramSignatureOutputStream);
      rawSignature = paramSignature;
    }
    
    public boolean verify(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
    {
      try
      {
        rawSignature.update(paramArrayOfByte1);
        return rawSignature.verify(paramArrayOfByte2);
      }
      catch (SignatureException localSignatureException)
      {
        throw new RuntimeOperatorException("exception obtaining raw signature: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
  }
  
  private class SigVerifier
    implements ContentVerifier
  {
    private JcaContentVerifierProviderBuilder.SignatureOutputStream stream;
    private AlgorithmIdentifier algorithm;
    
    SigVerifier(AlgorithmIdentifier paramAlgorithmIdentifier, JcaContentVerifierProviderBuilder.SignatureOutputStream paramSignatureOutputStream)
    {
      algorithm = paramAlgorithmIdentifier;
      stream = paramSignatureOutputStream;
    }
    
    public AlgorithmIdentifier getAlgorithmIdentifier()
    {
      return algorithm;
    }
    
    public OutputStream getOutputStream()
    {
      if (stream == null) {
        throw new IllegalStateException("verifier not initialised");
      }
      return stream;
    }
    
    public boolean verify(byte[] paramArrayOfByte)
    {
      try
      {
        return stream.verify(paramArrayOfByte);
      }
      catch (SignatureException localSignatureException)
      {
        throw new RuntimeOperatorException("exception obtaining signature: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
  }
  
  private class SignatureOutputStream
    extends OutputStream
  {
    private Signature sig;
    
    SignatureOutputStream(Signature paramSignature)
    {
      sig = paramSignature;
    }
    
    public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
      try
      {
        sig.update(paramArrayOfByte, paramInt1, paramInt2);
      }
      catch (SignatureException localSignatureException)
      {
        throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
    
    public void write(byte[] paramArrayOfByte)
      throws IOException
    {
      try
      {
        sig.update(paramArrayOfByte);
      }
      catch (SignatureException localSignatureException)
      {
        throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
    
    public void write(int paramInt)
      throws IOException
    {
      try
      {
        sig.update((byte)paramInt);
      }
      catch (SignatureException localSignatureException)
      {
        throw new OperatorStreamException("exception in content signer: " + localSignatureException.getMessage(), localSignatureException);
      }
    }
    
    boolean verify(byte[] paramArrayOfByte)
      throws SignatureException
    {
      return sig.verify(paramArrayOfByte);
    }
  }
}

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

import java.io.OutputStream;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.operator.DigestCalculator;

class JcaDigestCalculatorProviderBuilder$1$1
  implements DigestCalculator
{
  JcaDigestCalculatorProviderBuilder$1$1(JcaDigestCalculatorProviderBuilder.1 param1, AlgorithmIdentifier paramAlgorithmIdentifier, JcaDigestCalculatorProviderBuilder.DigestOutputStream paramDigestOutputStream) {}
  
  public AlgorithmIdentifier getAlgorithmIdentifier()
  {
    return val$algorithm;
  }
  
  public OutputStream getOutputStream()
  {
    return val$stream;
  }
  
  public byte[] getDigest()
  {
    return val$stream.getDigest();
  }
}

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

import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;

class JcaDigestCalculatorProviderBuilder$1
  implements DigestCalculatorProvider
{
  JcaDigestCalculatorProviderBuilder$1(JcaDigestCalculatorProviderBuilder paramJcaDigestCalculatorProviderBuilder)
    throws OperatorCreationException
  {}
  
  public DigestCalculator get(final AlgorithmIdentifier paramAlgorithmIdentifier)
    throws OperatorCreationException
  {
    final JcaDigestCalculatorProviderBuilder.DigestOutputStream localDigestOutputStream;
    try
    {
      MessageDigest localMessageDigest = JcaDigestCalculatorProviderBuilder.access$000(this$0).createDigest(paramAlgorithmIdentifier);
      localDigestOutputStream = new JcaDigestCalculatorProviderBuilder.DigestOutputStream(this$0, localMessageDigest);
    }
    catch (GeneralSecurityException localGeneralSecurityException)
    {
      throw new OperatorCreationException("exception on setup: " + localGeneralSecurityException, localGeneralSecurityException);
    }
    new DigestCalculator()
    {
      public AlgorithmIdentifier getAlgorithmIdentifier()
      {
        return paramAlgorithmIdentifier;
      }
      
      public OutputStream getOutputStream()
      {
        return localDigestOutputStream;
      }
      
      public byte[] getDigest()
      {
        return localDigestOutputStream.getDigest();
      }
    };
  }
}

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

import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;

class JcaDigestCalculatorProviderBuilder$DigestOutputStream
  extends OutputStream
{
  private MessageDigest dig;
  
  JcaDigestCalculatorProviderBuilder$DigestOutputStream(JcaDigestCalculatorProviderBuilder paramJcaDigestCalculatorProviderBuilder, MessageDigest paramMessageDigest)
  {
    dig = paramMessageDigest;
  }
  
  public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
    throws IOException
  {
    dig.update(paramArrayOfByte, paramInt1, paramInt2);
  }
  
  public void write(byte[] paramArrayOfByte)
    throws IOException
  {
    dig.update(paramArrayOfByte);
  }
  
  public void write(int paramInt)
    throws IOException
  {
    dig.update((byte)paramInt);
  }
  
  byte[] getDigest()
  {
    return dig.digest();
  }
}

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

import java.io.IOException;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.Provider;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.jcajce.DefaultJcaJceHelper;
import org.bouncycastle.jcajce.NamedJcaJceHelper;
import org.bouncycastle.jcajce.ProviderJcaJceHelper;
import org.bouncycastle.operator.DigestCalculator;
import org.bouncycastle.operator.DigestCalculatorProvider;
import org.bouncycastle.operator.OperatorCreationException;

public class JcaDigestCalculatorProviderBuilder
{
  private OperatorHelper helper = new OperatorHelper(new DefaultJcaJceHelper());
  
  public JcaDigestCalculatorProviderBuilder setProvider(Provider paramProvider)
  {
    helper = new OperatorHelper(new ProviderJcaJceHelper(paramProvider));
    return this;
  }
  
  public JcaDigestCalculatorProviderBuilder setProvider(String paramString)
  {
    helper = new OperatorHelper(new NamedJcaJceHelper(paramString));
    return this;
  }
  
  public DigestCalculatorProvider build()
    throws OperatorCreationException
  {
    new DigestCalculatorProvider()
    {
      public DigestCalculator get(final AlgorithmIdentifier paramAnonymousAlgorithmIdentifier)
        throws OperatorCreationException
      {
        final JcaDigestCalculatorProviderBuilder.DigestOutputStream localDigestOutputStream;
        try
        {
          MessageDigest localMessageDigest = helper.createDigest(paramAnonymousAlgorithmIdentifier);
          localDigestOutputStream = new JcaDigestCalculatorProviderBuilder.DigestOutputStream(JcaDigestCalculatorProviderBuilder.this, localMessageDigest);
        }
        catch (GeneralSecurityException localGeneralSecurityException)
        {
          throw new OperatorCreationException("exception on setup: " + localGeneralSecurityException, localGeneralSecurityException);
        }
        new DigestCalculator()
        {
          public AlgorithmIdentifier getAlgorithmIdentifier()
          {
            return paramAnonymousAlgorithmIdentifier;
          }
          
          public OutputStream getOutputStream()
          {
            return localDigestOutputStream;
          }
          
          public byte[] getDigest()
          {
            return localDigestOutputStream.getDigest();
          }
        };
      }
    };
  }
  
  private class DigestOutputStream
    extends OutputStream
  {
    private MessageDigest dig;
    
    DigestOutputStream(MessageDigest paramMessageDigest)
    {
      dig = paramMessageDigest;
    }
    
    public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
      dig.update(paramArrayOfByte, paramInt1, paramInt2);
    }
    
    public void write(byte[] paramArrayOfByte)
      throws IOException
    {
      dig.update(paramArrayOfByte);
    }
    
    public void write(int paramInt)
      throws IOException
    {
      dig.update((byte)paramInt);
    }
    
    byte[] getDigest()
    {
      return dig.digest();
    }
  }
}

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

import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.ProviderException;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.jcajce.DefaultJcaJceHelper;
import org.bouncycastle.jcajce.NamedJcaJceHelper;
import org.bouncycastle.jcajce.ProviderJcaJceHelper;
import org.bouncycastle.operator.AsymmetricKeyUnwrapper;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.OperatorException;

public class JceAsymmetricKeyUnwrapper
  extends AsymmetricKeyUnwrapper
{
  private OperatorHelper helper = new OperatorHelper(new DefaultJcaJceHelper());
  private Map extraMappings = new HashMap();
  private PrivateKey privKey;
  
  public JceAsymmetricKeyUnwrapper(AlgorithmIdentifier paramAlgorithmIdentifier, PrivateKey paramPrivateKey)
  {
    super(paramAlgorithmIdentifier);
    privKey = paramPrivateKey;
  }
  
  public JceAsymmetricKeyUnwrapper setProvider(Provider paramProvider)
  {
    helper = new OperatorHelper(new ProviderJcaJceHelper(paramProvider));
    return this;
  }
  
  public JceAsymmetricKeyUnwrapper setProvider(String paramString)
  {
    helper = new OperatorHelper(new NamedJcaJceHelper(paramString));
    return this;
  }
  
  public JceAsymmetricKeyUnwrapper setAlgorithmMapping(ASN1ObjectIdentifier paramASN1ObjectIdentifier, String paramString)
  {
    extraMappings.put(paramASN1ObjectIdentifier, paramString);
    return this;
  }
  
  public GenericKey generateUnwrappedKey(AlgorithmIdentifier paramAlgorithmIdentifier, byte[] paramArrayOfByte)
    throws OperatorException
  {
    try
    {
      Object localObject = null;
      Cipher localCipher = helper.createAsymmetricWrapper(getAlgorithmIdentifier().getAlgorithm(), extraMappings);
      try
      {
        localCipher.init(4, privKey);
        localObject = localCipher.unwrap(paramArrayOfByte, helper.getKeyAlgorithmName(paramAlgorithmIdentifier.getAlgorithm()), 3);
      }
      catch (GeneralSecurityException localGeneralSecurityException) {}catch (IllegalStateException localIllegalStateException) {}catch (UnsupportedOperationException localUnsupportedOperationException) {}catch (ProviderException localProviderException) {}
      if (localObject == null)
      {
        localCipher.init(2, privKey);
        localObject = new SecretKeySpec(localCipher.doFinal(paramArrayOfByte), paramAlgorithmIdentifier.getAlgorithm().getId());
      }
      return new GenericKey(localObject);
    }
    catch (InvalidKeyException localInvalidKeyException)
    {
      throw new OperatorException("key invalid: " + localInvalidKeyException.getMessage(), localInvalidKeyException);
    }
    catch (IllegalBlockSizeException localIllegalBlockSizeException)
    {
      throw new OperatorException("illegal blocksize: " + localIllegalBlockSizeException.getMessage(), localIllegalBlockSizeException);
    }
    catch (BadPaddingException localBadPaddingException)
    {
      throw new OperatorException("bad padding: " + localBadPaddingException.getMessage(), localBadPaddingException);
    }
  }
}

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

import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.Provider;
import java.security.ProviderException;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.Cipher;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.jcajce.DefaultJcaJceHelper;
import org.bouncycastle.jcajce.NamedJcaJceHelper;
import org.bouncycastle.jcajce.ProviderJcaJceHelper;
import org.bouncycastle.operator.AsymmetricKeyWrapper;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.OperatorException;

public class JceAsymmetricKeyWrapper
  extends AsymmetricKeyWrapper
{
  private OperatorHelper helper = new OperatorHelper(new DefaultJcaJceHelper());
  private Map extraMappings = new HashMap();
  private PublicKey publicKey;
  private SecureRandom random;
  
  public JceAsymmetricKeyWrapper(PublicKey paramPublicKey)
  {
    super(SubjectPublicKeyInfo.getInstance(paramPublicKey.getEncoded()).getAlgorithm());
    publicKey = paramPublicKey;
  }
  
  public JceAsymmetricKeyWrapper(X509Certificate paramX509Certificate)
  {
    this(paramX509Certificate.getPublicKey());
  }
  
  public JceAsymmetricKeyWrapper setProvider(Provider paramProvider)
  {
    helper = new OperatorHelper(new ProviderJcaJceHelper(paramProvider));
    return this;
  }
  
  public JceAsymmetricKeyWrapper setProvider(String paramString)
  {
    helper = new OperatorHelper(new NamedJcaJceHelper(paramString));
    return this;
  }
  
  public JceAsymmetricKeyWrapper setSecureRandom(SecureRandom paramSecureRandom)
  {
    random = paramSecureRandom;
    return this;
  }
  
  public JceAsymmetricKeyWrapper setAlgorithmMapping(ASN1ObjectIdentifier paramASN1ObjectIdentifier, String paramString)
  {
    extraMappings.put(paramASN1ObjectIdentifier, paramString);
    return this;
  }
  
  public byte[] generateWrappedKey(GenericKey paramGenericKey)
    throws OperatorException
  {
    Cipher localCipher = helper.createAsymmetricWrapper(getAlgorithmIdentifier().getAlgorithm(), extraMappings);
    byte[] arrayOfByte = null;
    try
    {
      localCipher.init(3, publicKey, random);
      arrayOfByte = localCipher.wrap(OperatorUtils.getJceKey(paramGenericKey));
    }
    catch (GeneralSecurityException localGeneralSecurityException1) {}catch (IllegalStateException localIllegalStateException) {}catch (UnsupportedOperationException localUnsupportedOperationException) {}catch (ProviderException localProviderException) {}
    if (arrayOfByte == null) {
      try
      {
        localCipher.init(1, publicKey, random);
        arrayOfByte = localCipher.doFinal(OperatorUtils.getJceKey(paramGenericKey).getEncoded());
      }
      catch (GeneralSecurityException localGeneralSecurityException2)
      {
        throw new OperatorException("unable to encrypt contents key", localGeneralSecurityException2);
      }
    }
    return arrayOfByte;
  }
}

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

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.jcajce.DefaultJcaJceHelper;
import org.bouncycastle.jcajce.NamedJcaJceHelper;
import org.bouncycastle.jcajce.ProviderJcaJceHelper;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.OperatorException;
import org.bouncycastle.operator.SymmetricKeyUnwrapper;

public class JceSymmetricKeyUnwrapper
  extends SymmetricKeyUnwrapper
{
  private OperatorHelper helper = new OperatorHelper(new DefaultJcaJceHelper());
  private SecretKey secretKey;
  
  public JceSymmetricKeyUnwrapper(AlgorithmIdentifier paramAlgorithmIdentifier, SecretKey paramSecretKey)
  {
    super(paramAlgorithmIdentifier);
    secretKey = paramSecretKey;
  }
  
  public JceSymmetricKeyUnwrapper setProvider(Provider paramProvider)
  {
    helper = new OperatorHelper(new ProviderJcaJceHelper(paramProvider));
    return this;
  }
  
  public JceSymmetricKeyUnwrapper setProvider(String paramString)
  {
    helper = new OperatorHelper(new NamedJcaJceHelper(paramString));
    return this;
  }
  
  public GenericKey generateUnwrappedKey(AlgorithmIdentifier paramAlgorithmIdentifier, byte[] paramArrayOfByte)
    throws OperatorException
  {
    try
    {
      Cipher localCipher = helper.createSymmetricWrapper(getAlgorithmIdentifier().getAlgorithm());
      localCipher.init(4, secretKey);
      return new GenericKey(localCipher.unwrap(paramArrayOfByte, helper.getKeyAlgorithmName(paramAlgorithmIdentifier.getAlgorithm()), 3));
    }
    catch (InvalidKeyException localInvalidKeyException)
    {
      throw new OperatorException("key invalid in message.", localInvalidKeyException);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new OperatorException("can't find algorithm.", localNoSuchAlgorithmException);
    }
  }
}

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

import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.Provider;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.DERInteger;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.DERObjectIdentifier;
import org.bouncycastle.asn1.kisa.KISAObjectIdentifiers;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.asn1.ntt.NTTObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.jcajce.DefaultJcaJceHelper;
import org.bouncycastle.jcajce.NamedJcaJceHelper;
import org.bouncycastle.jcajce.ProviderJcaJceHelper;
import org.bouncycastle.operator.GenericKey;
import org.bouncycastle.operator.OperatorException;
import org.bouncycastle.operator.SymmetricKeyWrapper;

public class JceSymmetricKeyWrapper
  extends SymmetricKeyWrapper
{
  private OperatorHelper helper = new OperatorHelper(new DefaultJcaJceHelper());
  private SecureRandom random;
  private SecretKey wrappingKey;
  
  public JceSymmetricKeyWrapper(SecretKey paramSecretKey)
  {
    super(determineKeyEncAlg(paramSecretKey));
    wrappingKey = paramSecretKey;
  }
  
  public JceSymmetricKeyWrapper setProvider(Provider paramProvider)
  {
    helper = new OperatorHelper(new ProviderJcaJceHelper(paramProvider));
    return this;
  }
  
  public JceSymmetricKeyWrapper setProvider(String paramString)
  {
    helper = new OperatorHelper(new NamedJcaJceHelper(paramString));
    return this;
  }
  
  public JceSymmetricKeyWrapper setSecureRandom(SecureRandom paramSecureRandom)
  {
    random = paramSecureRandom;
    return this;
  }
  
  public byte[] generateWrappedKey(GenericKey paramGenericKey)
    throws OperatorException
  {
    Key localKey = OperatorUtils.getJceKey(paramGenericKey);
    Cipher localCipher = helper.createSymmetricWrapper(getAlgorithmIdentifier().getAlgorithm());
    try
    {
      localCipher.init(3, wrappingKey, random);
      return localCipher.wrap(localKey);
    }
    catch (GeneralSecurityException localGeneralSecurityException)
    {
      throw new OperatorException("cannot wrap key: " + localGeneralSecurityException.getMessage(), localGeneralSecurityException);
    }
  }
  
  private static AlgorithmIdentifier determineKeyEncAlg(SecretKey paramSecretKey)
  {
    String str = paramSecretKey.getAlgorithm();
    if (str.startsWith("DES")) {
      return new AlgorithmIdentifier(new DERObjectIdentifier("1.2.840.113549.1.9.16.3.6"), new DERNull());
    }
    if (str.startsWith("RC2")) {
      return new AlgorithmIdentifier(new DERObjectIdentifier("1.2.840.113549.1.9.16.3.7"), new DERInteger(58));
    }
    int i;
    ASN1ObjectIdentifier localASN1ObjectIdentifier;
    if (str.startsWith("AES"))
    {
      i = paramSecretKey.getEncoded().length * 8;
      if (i == 128) {
        localASN1ObjectIdentifier = NISTObjectIdentifiers.id_aes128_wrap;
      } else if (i == 192) {
        localASN1ObjectIdentifier = NISTObjectIdentifiers.id_aes192_wrap;
      } else if (i == 256) {
        localASN1ObjectIdentifier = NISTObjectIdentifiers.id_aes256_wrap;
      } else {
        throw new IllegalArgumentException("illegal keysize in AES");
      }
      return new AlgorithmIdentifier(localASN1ObjectIdentifier);
    }
    if (str.startsWith("SEED")) {
      return new AlgorithmIdentifier(KISAObjectIdentifiers.id_npki_app_cmsSeed_wrap);
    }
    if (str.startsWith("Camellia"))
    {
      i = paramSecretKey.getEncoded().length * 8;
      if (i == 128) {
        localASN1ObjectIdentifier = NTTObjectIdentifiers.id_camellia128_wrap;
      } else if (i == 192) {
        localASN1ObjectIdentifier = NTTObjectIdentifiers.id_camellia192_wrap;
      } else if (i == 256) {
        localASN1ObjectIdentifier = NTTObjectIdentifiers.id_camellia256_wrap;
      } else {
        throw new IllegalArgumentException("illegal keysize in Camellia");
      }
      return new AlgorithmIdentifier(localASN1ObjectIdentifier);
    }
    throw new IllegalArgumentException("unknown algorithm");
  }
}

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

import java.security.cert.CertificateException;

class OperatorHelper$OpCertificateException
  extends CertificateException
{
  private Throwable cause;
  
  public OperatorHelper$OpCertificateException(String paramString, Throwable paramThrowable)
  {
    super(paramString);
    cause = paramThrowable;
  }
  
  public Throwable getCause()
  {
    return cause;
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.AlgorithmParameters;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Signature;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.spec.PSSParameterSpec;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.Cipher;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
import org.bouncycastle.asn1.kisa.KISAObjectIdentifiers;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.asn1.ntt.NTTObjectIdentifiers;
import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.RSASSAPSSparams;
import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.jcajce.JcaJceHelper;
import org.bouncycastle.operator.OperatorCreationException;

class OperatorHelper
{
  private static final Map oids = new HashMap();
  private static final Map asymmetricWrapperAlgNames = new HashMap();
  private static final Map symmetricWrapperAlgNames = new HashMap();
  private static final Map symmetricKeyAlgNames = new HashMap();
  private JcaJceHelper helper;
  
  OperatorHelper(JcaJceHelper paramJcaJceHelper)
  {
    helper = paramJcaJceHelper;
  }
  
  Cipher createAsymmetricWrapper(ASN1ObjectIdentifier paramASN1ObjectIdentifier, Map paramMap)
    throws OperatorCreationException
  {
    try
    {
      String str = null;
      if (!paramMap.isEmpty()) {
        str = (String)paramMap.get(paramASN1ObjectIdentifier);
      }
      if (str == null) {
        str = (String)asymmetricWrapperAlgNames.get(paramASN1ObjectIdentifier);
      }
      if (str != null) {
        try
        {
          return helper.createCipher(str);
        }
        catch (NoSuchAlgorithmException localNoSuchAlgorithmException1)
        {
          if (str.equals("RSA/ECB/PKCS1Padding")) {
            try
            {
              return helper.createCipher("RSA/NONE/PKCS1Padding");
            }
            catch (NoSuchAlgorithmException localNoSuchAlgorithmException2) {}
          }
        }
      }
      return helper.createCipher(paramASN1ObjectIdentifier.getId());
    }
    catch (GeneralSecurityException localGeneralSecurityException)
    {
      throw new OperatorCreationException("cannot create cipher: " + localGeneralSecurityException.getMessage(), localGeneralSecurityException);
    }
  }
  
  Cipher createSymmetricWrapper(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
    throws OperatorCreationException
  {
    try
    {
      String str = (String)symmetricWrapperAlgNames.get(paramASN1ObjectIdentifier);
      if (str != null) {
        try
        {
          return helper.createCipher(str);
        }
        catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {}
      }
      return helper.createCipher(paramASN1ObjectIdentifier.getId());
    }
    catch (GeneralSecurityException localGeneralSecurityException)
    {
      throw new OperatorCreationException("cannot create cipher: " + localGeneralSecurityException.getMessage(), localGeneralSecurityException);
    }
  }
  
  MessageDigest createDigest(AlgorithmIdentifier paramAlgorithmIdentifier)
    throws GeneralSecurityException
  {
    MessageDigest localMessageDigest;
    try
    {
      localMessageDigest = helper.createDigest(getDigestAlgName(paramAlgorithmIdentifier.getAlgorithm()));
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      if (oids.get(paramAlgorithmIdentifier.getAlgorithm()) != null)
      {
        String str = (String)oids.get(paramAlgorithmIdentifier.getAlgorithm());
        localMessageDigest = helper.createDigest(str);
      }
      else
      {
        throw localNoSuchAlgorithmException;
      }
    }
    return localMessageDigest;
  }
  
  Signature createSignature(AlgorithmIdentifier paramAlgorithmIdentifier)
    throws GeneralSecurityException
  {
    Signature localSignature;
    try
    {
      localSignature = helper.createSignature(getSignatureName(paramAlgorithmIdentifier));
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      if (oids.get(paramAlgorithmIdentifier.getAlgorithm()) != null)
      {
        String str = (String)oids.get(paramAlgorithmIdentifier.getAlgorithm());
        localSignature = helper.createSignature(str);
      }
      else
      {
        throw localNoSuchAlgorithmException;
      }
    }
    return localSignature;
  }
  
  public Signature createRawSignature(AlgorithmIdentifier paramAlgorithmIdentifier)
  {
    Signature localSignature;
    try
    {
      String str = getSignatureName(paramAlgorithmIdentifier);
      str = "NONE" + str.substring(str.indexOf("WITH"));
      localSignature = helper.createSignature(str);
      if (paramAlgorithmIdentifier.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
      {
        AlgorithmParameters localAlgorithmParameters = helper.createAlgorithmParameters(str);
        localAlgorithmParameters.init(paramAlgorithmIdentifier.getParameters().toASN1Primitive().getEncoded(), "ASN.1");
        PSSParameterSpec localPSSParameterSpec = (PSSParameterSpec)localAlgorithmParameters.getParameterSpec(PSSParameterSpec.class);
        localSignature.setParameter(localPSSParameterSpec);
      }
    }
    catch (Exception localException)
    {
      return null;
    }
    return localSignature;
  }
  
  private static String getSignatureName(AlgorithmIdentifier paramAlgorithmIdentifier)
  {
    ASN1Encodable localASN1Encodable = paramAlgorithmIdentifier.getParameters();
    if ((localASN1Encodable != null) && (!DERNull.INSTANCE.equals(localASN1Encodable)) && (paramAlgorithmIdentifier.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)))
    {
      RSASSAPSSparams localRSASSAPSSparams = RSASSAPSSparams.getInstance(localASN1Encodable);
      return getDigestAlgName(localRSASSAPSSparams.getHashAlgorithm().getAlgorithm()) + "WITHRSAANDMGF1";
    }
    if (oids.containsKey(paramAlgorithmIdentifier.getAlgorithm())) {
      return (String)oids.get(paramAlgorithmIdentifier.getAlgorithm());
    }
    return paramAlgorithmIdentifier.getAlgorithm().getId();
  }
  
  private static String getDigestAlgName(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    if (PKCSObjectIdentifiers.md5.equals(paramASN1ObjectIdentifier)) {
      return "MD5";
    }
    if (OIWObjectIdentifiers.idSHA1.equals(paramASN1ObjectIdentifier)) {
      return "SHA1";
    }
    if (NISTObjectIdentifiers.id_sha224.equals(paramASN1ObjectIdentifier)) {
      return "SHA224";
    }
    if (NISTObjectIdentifiers.id_sha256.equals(paramASN1ObjectIdentifier)) {
      return "SHA256";
    }
    if (NISTObjectIdentifiers.id_sha384.equals(paramASN1ObjectIdentifier)) {
      return "SHA384";
    }
    if (NISTObjectIdentifiers.id_sha512.equals(paramASN1ObjectIdentifier)) {
      return "SHA512";
    }
    if (TeleTrusTObjectIdentifiers.ripemd128.equals(paramASN1ObjectIdentifier)) {
      return "RIPEMD128";
    }
    if (TeleTrusTObjectIdentifiers.ripemd160.equals(paramASN1ObjectIdentifier)) {
      return "RIPEMD160";
    }
    if (TeleTrusTObjectIdentifiers.ripemd256.equals(paramASN1ObjectIdentifier)) {
      return "RIPEMD256";
    }
    if (CryptoProObjectIdentifiers.gostR3411.equals(paramASN1ObjectIdentifier)) {
      return "GOST3411";
    }
    return paramASN1ObjectIdentifier.getId();
  }
  
  public X509Certificate convertCertificate(X509CertificateHolder paramX509CertificateHolder)
    throws CertificateException
  {
    try
    {
      CertificateFactory localCertificateFactory = helper.createCertificateFactory("X.509");
      return (X509Certificate)localCertificateFactory.generateCertificate(new ByteArrayInputStream(paramX509CertificateHolder.getEncoded()));
    }
    catch (IOException localIOException)
    {
      throw new OpCertificateException("cannot get encoded form of certificate: " + localIOException.getMessage(), localIOException);
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      throw new OpCertificateException("cannot create certificate factory: " + localNoSuchAlgorithmException.getMessage(), localNoSuchAlgorithmException);
    }
    catch (NoSuchProviderException localNoSuchProviderException)
    {
      throw new OpCertificateException("cannot find factory provider: " + localNoSuchProviderException.getMessage(), localNoSuchProviderException);
    }
  }
  
  String getKeyAlgorithmName(ASN1ObjectIdentifier paramASN1ObjectIdentifier)
  {
    String str = (String)symmetricKeyAlgNames.get(paramASN1ObjectIdentifier);
    if (str != null) {
      return str;
    }
    return paramASN1ObjectIdentifier.getId();
  }
  
  static
  {
    oids.put(new ASN1ObjectIdentifier("1.2.840.113549.1.1.5"), "SHA1WITHRSA");
    oids.put(PKCSObjectIdentifiers.sha224WithRSAEncryption, "SHA224WITHRSA");
    oids.put(PKCSObjectIdentifiers.sha256WithRSAEncryption, "SHA256WITHRSA");
    oids.put(PKCSObjectIdentifiers.sha384WithRSAEncryption, "SHA384WITHRSA");
    oids.put(PKCSObjectIdentifiers.sha512WithRSAEncryption, "SHA512WITHRSA");
    oids.put(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94, "GOST3411WITHGOST3410");
    oids.put(Crypto
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