Java 类org.bouncycastle.crypto.AsymmetricBlockCipher 实例源码

项目:ipack    文件:BcAsymmetricKeyUnwrapper.java   
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyCipher = createAsymmetricUnwrapper(this.getAlgorithmIdentifier().getAlgorithm());

    keyCipher.init(false, privateKey);
    try
    {
        byte[] key = keyCipher.processBlock(encryptedKey, 0, encryptedKey.length);

        if (encryptedKeyAlgorithm.getAlgorithm().equals(PKCSObjectIdentifiers.des_EDE3_CBC))
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
        else
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to recover secret key: " + e.getMessage(), e);
    }
}
项目:ipack    文件:OAEPEncoding.java   
public OAEPEncoding(
    AsymmetricBlockCipher       cipher,
    Digest                      hash,
    Digest                      mgf1Hash,
    byte[]                      encodingParams)
{
    this.engine = cipher;
    this.mgf1Hash = mgf1Hash;
    this.defHash = new byte[hash.getDigestSize()];

    hash.reset();

    if (encodingParams != null)
    {
        hash.update(encodingParams, 0, encodingParams.length);
    }

    hash.doFinal(defHash, 0);
}
项目:ipack    文件:PSSSigner.java   
public PSSSigner(
    AsymmetricBlockCipher   cipher,
    Digest                  contentDigest,
    Digest                  mgfDigest,
    int                     sLen,
    byte                    trailer)
{
    this.cipher = cipher;
    this.contentDigest = contentDigest;
    this.mgfDigest = mgfDigest;
    this.hLen = contentDigest.getDigestSize();
    this.mgfhLen = mgfDigest.getDigestSize();
    this.sLen = sLen;
    this.salt = new byte[sLen];
    this.mDash = new byte[8 + sLen + hLen];
    this.trailer = trailer;
}
项目:ipack    文件:PSSSignatureSpi.java   
protected PSSSignatureSpi(
    AsymmetricBlockCipher signer,
    PSSParameterSpec baseParamSpec,
    boolean isRaw)
{
    this.signer = signer;
    this.originalSpec = baseParamSpec;

    if (baseParamSpec == null)
    {
        this.paramSpec = PSSParameterSpec.DEFAULT;
    }
    else
    {
        this.paramSpec = baseParamSpec;
    }

    this.mgfDigest = DigestFactory.getDigest(paramSpec.getDigestAlgorithm());
    this.saltLength = paramSpec.getSaltLength();
    this.trailer = getTrailer(paramSpec.getTrailerField());
    this.isRaw = isRaw;

    setupContentDigest();
}
项目:Direct-File-Downloader    文件:OAEPEncoding.java   
public OAEPEncoding(
    AsymmetricBlockCipher       cipher,
    Digest                          hash,
    byte[]                          encodingParams)
{
    this.engine = cipher;
    this.hash = hash;
    this.defHash = new byte[hash.getDigestSize()];

       if (encodingParams != null)
       {
        hash.update(encodingParams, 0, encodingParams.length);
       }

    hash.doFinal(defHash, 0);
}
项目:gwt-crypto    文件:BcAsymmetricKeyUnwrapper.java   
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyCipher = createAsymmetricUnwrapper(this.getAlgorithmIdentifier().getAlgorithm());

    keyCipher.init(false, privateKey);
    try
    {
        byte[] key = keyCipher.processBlock(encryptedKey, 0, encryptedKey.length);

        if (encryptedKeyAlgorithm.getAlgorithm().equals(PKCSObjectIdentifiers.des_EDE3_CBC))
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
        else
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to recover secret key: " + e.getMessage(), e);
    }
}
项目:gwt-crypto    文件:OAEPEncoding.java   
public OAEPEncoding(
    AsymmetricBlockCipher       cipher,
    Digest                      hash,
    Digest                      mgf1Hash,
    byte[]                      encodingParams)
{
    this.engine = cipher;
    this.mgf1Hash = mgf1Hash;
    this.defHash = new byte[hash.getDigestSize()];

    hash.reset();

    if (encodingParams != null)
    {
        hash.update(encodingParams, 0, encodingParams.length);
    }

    hash.doFinal(defHash, 0);
}
项目:gwt-crypto    文件:PSSSigner.java   
public PSSSigner(
    AsymmetricBlockCipher   cipher,
    Digest                  contentDigest,
    Digest                  mgfDigest,
    int                     sLen,
    byte                    trailer)
{
    this.cipher = cipher;
    this.contentDigest = contentDigest;
    this.mgfDigest = mgfDigest;
    this.hLen = contentDigest.getDigestSize();
    this.mgfhLen = mgfDigest.getDigestSize();
    this.sSet = false;
    this.sLen = sLen;
    this.salt = new byte[sLen];
    this.mDash = new byte[8 + sLen + hLen];
    this.trailer = trailer;
}
项目:gwt-crypto    文件:PSSSigner.java   
public PSSSigner(
    AsymmetricBlockCipher   cipher,
    Digest                  contentDigest,
    Digest                  mgfDigest,
    byte[]                  salt,
    byte                    trailer)
{
    this.cipher = cipher;
    this.contentDigest = contentDigest;
    this.mgfDigest = mgfDigest;
    this.hLen = contentDigest.getDigestSize();
    this.mgfhLen = mgfDigest.getDigestSize();
    this.sSet = true;
    this.sLen = salt.length;
    this.salt = salt;
    this.mDash = new byte[8 + sLen + hLen];
    this.trailer = trailer;
}
项目:Aki-SSL    文件:BcAsymmetricKeyUnwrapper.java   
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyCipher = createAsymmetricUnwrapper(this.getAlgorithmIdentifier().getAlgorithm());

    keyCipher.init(false, privateKey);
    try
    {
        byte[] key = keyCipher.processBlock(encryptedKey, 0, encryptedKey.length);

        if (encryptedKeyAlgorithm.getAlgorithm().equals(PKCSObjectIdentifiers.des_EDE3_CBC))
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
        else
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to recover secret key: " + e.getMessage(), e);
    }
}
项目:Aki-SSL    文件:OAEPEncoding.java   
public OAEPEncoding(
    AsymmetricBlockCipher       cipher,
    Digest                      hash,
    Digest                      mgf1Hash,
    byte[]                      encodingParams)
{
    this.engine = cipher;
    this.mgf1Hash = mgf1Hash;
    this.defHash = new byte[hash.getDigestSize()];

    hash.reset();

    if (encodingParams != null)
    {
        hash.update(encodingParams, 0, encodingParams.length);
    }

    hash.doFinal(defHash, 0);
}
项目:Aki-SSL    文件:PSSSigner.java   
public PSSSigner(
    AsymmetricBlockCipher   cipher,
    Digest                  contentDigest,
    Digest                  mgfDigest,
    int                     sLen,
    byte                    trailer)
{
    this.cipher = cipher;
    this.contentDigest = contentDigest;
    this.mgfDigest = mgfDigest;
    this.hLen = contentDigest.getDigestSize();
    this.mgfhLen = mgfDigest.getDigestSize();
    this.sSet = false;
    this.sLen = sLen;
    this.salt = new byte[sLen];
    this.mDash = new byte[8 + sLen + hLen];
    this.trailer = trailer;
}
项目:Aki-SSL    文件:PSSSigner.java   
public PSSSigner(
    AsymmetricBlockCipher   cipher,
    Digest                  contentDigest,
    Digest                  mgfDigest,
    byte[]                  salt,
    byte                    trailer)
{
    this.cipher = cipher;
    this.contentDigest = contentDigest;
    this.mgfDigest = mgfDigest;
    this.hLen = contentDigest.getDigestSize();
    this.mgfhLen = mgfDigest.getDigestSize();
    this.sSet = true;
    this.sLen = salt.length;
    this.salt = salt;
    this.mDash = new byte[8 + sLen + hLen];
    this.trailer = trailer;
}
项目:Aki-SSL    文件:PSSSignatureSpi.java   
protected PSSSignatureSpi(
    AsymmetricBlockCipher signer,
    PSSParameterSpec baseParamSpec,
    boolean isRaw)
{
    this.signer = signer;
    this.originalSpec = baseParamSpec;

    if (baseParamSpec == null)
    {
        this.paramSpec = PSSParameterSpec.DEFAULT;
    }
    else
    {
        this.paramSpec = baseParamSpec;
    }

    this.mgfDigest = DigestFactory.getDigest(paramSpec.getDigestAlgorithm());
    this.saltLength = paramSpec.getSaltLength();
    this.trailer = getTrailer(paramSpec.getTrailerField());
    this.isRaw = isRaw;

    setupContentDigest();
}
项目:TinyTravelTracker    文件:OAEPEncoding.java   
public OAEPEncoding(
    AsymmetricBlockCipher       cipher,
    Digest                      hash,
    Digest                      mgf1Hash,
    byte[]                      encodingParams)
{
    this.engine = cipher;
    this.mgf1Hash = mgf1Hash;
    this.defHash = new byte[hash.getDigestSize()];

    hash.reset();

    if (encodingParams != null)
    {
        hash.update(encodingParams, 0, encodingParams.length);
    }

    hash.doFinal(defHash, 0);
}
项目:TinyTravelTracker    文件:PSSSigner.java   
public PSSSigner(
    AsymmetricBlockCipher   cipher,
    Digest                  contentDigest,
    Digest                  mgfDigest,
    int                     sLen,
    byte                    trailer)
{
    this.cipher = cipher;
    this.contentDigest = contentDigest;
    this.mgfDigest = mgfDigest;
    this.hLen = contentDigest.getDigestSize();
    this.mgfhLen = mgfDigest.getDigestSize();
    this.sLen = sLen;
    this.salt = new byte[sLen];
    this.mDash = new byte[8 + sLen + hLen];
    this.trailer = trailer;
}
项目:subshare    文件:CryptoRegistry.java   
private Cipher createCipherForAsymmetricBlockCipherMode(final String transformation, final AsymmetricBlockCipher modeWithEngine, final String engineName, final String modeName, final String paddingName)
throws NoSuchPaddingException
{
    AsymmetricBlockCipher padding;
    if (paddingName.isEmpty() || "NOPADDING".equals(paddingName))
        padding = modeWithEngine;
    else {
        padding = createAsymmetricBlockCipherPadding(paddingName, modeWithEngine);
        if (padding == null)
            throw new NoSuchPaddingException("There is no asymmetric-block-cipher-padding registered with name \"" + paddingName + "\"!");
    }

    return new AsymmetricBlockCipherImpl(
            transformation,
            new BufferedAsymmetricBlockCipher(padding)
    );
}
项目:africhat-platform-0.1    文件:OAEPEncoding.java   
public OAEPEncoding(
        AsymmetricBlockCipher cipher,
        Digest hash,
        Digest mgf1Hash,
        byte[] encodingParams) {
    this.engine = cipher;
    this.mgf1Hash = mgf1Hash;
    this.defHash = new byte[hash.getDigestSize()];

    hash.reset();

    if (encodingParams != null) {
        hash.update(encodingParams, 0, encodingParams.length);
    }

    hash.doFinal(defHash, 0);
}
项目:AcademicTorrents-Downloader    文件:OAEPEncoding.java   
public OAEPEncoding(
    AsymmetricBlockCipher       cipher,
    Digest                          hash,
    byte[]                          encodingParams)
{
    this.engine = cipher;
    this.hash = hash;
    this.defHash = new byte[hash.getDigestSize()];

       if (encodingParams != null)
       {
        hash.update(encodingParams, 0, encodingParams.length);
       }

    hash.doFinal(defHash, 0);
}
项目:cypher    文件:RSAKey.java   
/**
 * @return an RSA decryption cipher
 */
protected synchronized AsymmetricBlockCipher getRSADecryptCipher()
{
    if (decodeCipher == null)
    {
        try
        {
            byte[] bytes = getEncoder().decode(privateKey);
            EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(bytes);

            KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
            PrivateKey key = keyFactory.generatePrivate(privateKeySpec);

            this.decodeCipher = new PKCS1Encoding(new RSABlindedEngine());
            decodeCipher.init(false, generatePrivateKeyParameter((RSAPrivateKey) key));
        }
        catch (Exception e)
        {
            throw new RuntimeException("Error constructing Cipher: ", e);
        }
    }

    return decodeCipher;
}
项目:cypher    文件:RSAKey.java   
/**
 * @return
 */
protected synchronized AsymmetricBlockCipher getRSAEncryptCipher()
{
    if (encodeCipher == null)
    {
        try
        {
            byte[] bytes = getEncoder().decode(publicKey);
            EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(bytes);

            KeyFactory keyFactory = KeyFactory.getInstance(RSA_ALGORITHM);
            PublicKey key = keyFactory.generatePublic(publicKeySpec);

            this.encodeCipher = new PKCS1Encoding(new RSABlindedEngine());
            encodeCipher.init(true, generatePublicKeyParameter((RSAPublicKey) key));
        }
        catch (Exception e)
        {
            throw new RuntimeException("Error constructing Cipher: ", e);
        }
    }

    return encodeCipher;
}
项目:CryptMeme    文件:BcPublicKeyKeyEncryptionMethodGenerator.java   
protected byte[] encryptSessionInfo(PGPPublicKey pubKey, byte[] sessionInfo)
    throws PGPException
{
    try
    {
        AsymmetricBlockCipher c = BcImplProvider.createPublicKeyCipher(pubKey.getAlgorithm());

        AsymmetricKeyParameter key = keyConverter.getPublicKey(pubKey);

        if (random == null)
        {
            random = new SecureRandom();
        }

        c.init(true, new ParametersWithRandom(key, random));

        return c.processBlock(sessionInfo, 0, sessionInfo.length);
    }
    catch (InvalidCipherTextException e)
    {
        throw new PGPException("exception encrypting session info: " + e.getMessage(), e);
    }
}
项目:CryptMeme    文件:OAEPEncoding.java   
public OAEPEncoding(
    AsymmetricBlockCipher       cipher,
    Digest                      hash,
    Digest                      mgf1Hash,
    byte[]                      encodingParams)
{
    this.engine = cipher;
    this.mgf1Hash = mgf1Hash;
    this.defHash = new byte[hash.getDigestSize()];

    hash.reset();

    if (encodingParams != null)
    {
        hash.update(encodingParams, 0, encodingParams.length);
    }

    hash.doFinal(defHash, 0);
}
项目:CryptMeme    文件:PSSSigner.java   
public PSSSigner(
    AsymmetricBlockCipher   cipher,
    Digest                  contentDigest,
    Digest                  mgfDigest,
    int                     sLen,
    byte                    trailer)
{
    this.cipher = cipher;
    this.contentDigest = contentDigest;
    this.mgfDigest = mgfDigest;
    this.hLen = contentDigest.getDigestSize();
    this.mgfhLen = mgfDigest.getDigestSize();
    this.sLen = sLen;
    this.salt = new byte[sLen];
    this.mDash = new byte[8 + sLen + hLen];
    this.trailer = trailer;
}
项目:CryptMeme    文件:PSSSignatureSpi.java   
protected PSSSignatureSpi(
    AsymmetricBlockCipher signer,
    PSSParameterSpec baseParamSpec,
    boolean isRaw)
{
    this.signer = signer;
    this.originalSpec = baseParamSpec;

    if (baseParamSpec == null)
    {
        this.paramSpec = PSSParameterSpec.DEFAULT;
    }
    else
    {
        this.paramSpec = baseParamSpec;
    }

    this.mgfDigest = DigestFactory.getDigest(paramSpec.getDigestAlgorithm());
    this.saltLength = paramSpec.getSaltLength();
    this.trailer = getTrailer(paramSpec.getTrailerField());
    this.isRaw = isRaw;

    setupContentDigest();
}
项目:dxcrypto    文件:BouncyCastleRSAEngine.java   
private byte[] doOperation(byte[] input, boolean isEncrypt) {
    AsymmetricBlockCipher cipher = new OAEPEncoding(new RSAEngine(), new SHA256Digest(), new SHA1Digest(), null);
    RSAKeyParameters key = isEncrypt ? publicKey : privateKey;
    cipher.init(isEncrypt, key);
    try {
        return cipher.processBlock(input, 0, input.length);
    } catch (InvalidCipherTextException e) {
        throw new EncryptionException("Encryption fails", e);
    }
}
项目:irma_future_id    文件:BcAsymmetricKeyWrapper.java   
public byte[] generateWrappedKey(GenericKey encryptionKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyEncryptionCipher = createAsymmetricWrapper(getAlgorithmIdentifier().getAlgorithm());

    CipherParameters params = publicKey;
    if (random != null)
    {
        params = new ParametersWithRandom(params, random);
    }

    try
    {
        byte[] keyEnc = OperatorUtils.getKeyBytes(encryptionKey);
        keyEncryptionCipher.init(true, publicKey);
        return keyEncryptionCipher.processBlock(keyEnc, 0, keyEnc.length);
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to encrypt contents key", e);
    }
}
项目:irma_future_id    文件:BcAsymmetricKeyUnwrapper.java   
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyCipher = createAsymmetricUnwrapper(this.getAlgorithmIdentifier().getAlgorithm());

    keyCipher.init(false, privateKey);
    try
    {
        byte[] key = keyCipher.processBlock(encryptedKey, 0, encryptedKey.length);

        if (encryptedKeyAlgorithm.getAlgorithm().equals(PKCSObjectIdentifiers.des_EDE3_CBC))
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
        else
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to recover secret key: " + e.getMessage(), e);
    }
}
项目:irma_future_id    文件:BcPublicKeyKeyEncryptionMethodGenerator.java   
protected byte[] encryptSessionInfo(PGPPublicKey pubKey, byte[] sessionInfo)
    throws PGPException
{
    try
    {
        AsymmetricBlockCipher c = BcImplProvider.createPublicKeyCipher(pubKey.getAlgorithm());

        AsymmetricKeyParameter key = keyConverter.getPublicKey(pubKey);

        if (random == null)
        {
            random = new SecureRandom();
        }

        c.init(true, new ParametersWithRandom(key, random));

        return c.processBlock(sessionInfo, 0, sessionInfo.length);
    }
    catch (InvalidCipherTextException e)
    {
        throw new PGPException("exception encrypting session info: " + e.getMessage(), e);
    }
}
项目:irma_future_id    文件:OAEPEncoding.java   
public OAEPEncoding(
    AsymmetricBlockCipher       cipher,
    Digest                      hash,
    Digest                      mgf1Hash,
    byte[]                      encodingParams)
{
    this.engine = cipher;
    this.mgf1Hash = mgf1Hash;
    this.defHash = new byte[hash.getDigestSize()];

    hash.reset();

    if (encodingParams != null)
    {
        hash.update(encodingParams, 0, encodingParams.length);
    }

    hash.doFinal(defHash, 0);
}
项目:irma_future_id    文件:PSSSigner.java   
public PSSSigner(
    AsymmetricBlockCipher   cipher,
    Digest                  contentDigest,
    Digest                  mgfDigest,
    int                     sLen,
    byte                    trailer)
{
    this.cipher = cipher;
    this.contentDigest = contentDigest;
    this.mgfDigest = mgfDigest;
    this.hLen = contentDigest.getDigestSize();
    this.mgfhLen = mgfDigest.getDigestSize();
    this.sLen = sLen;
    this.salt = new byte[sLen];
    this.mDash = new byte[8 + sLen + hLen];
    this.trailer = trailer;
}
项目:irma_future_id    文件:PSSSignatureSpi.java   
protected PSSSignatureSpi(
    AsymmetricBlockCipher signer,
    PSSParameterSpec baseParamSpec,
    boolean isRaw)
{
    this.signer = signer;
    this.originalSpec = baseParamSpec;

    if (baseParamSpec == null)
    {
        this.paramSpec = PSSParameterSpec.DEFAULT;
    }
    else
    {
        this.paramSpec = baseParamSpec;
    }

    this.mgfDigest = DigestFactory.getDigest(paramSpec.getDigestAlgorithm());
    this.saltLength = paramSpec.getSaltLength();
    this.trailer = getTrailer(paramSpec.getTrailerField());
    this.isRaw = isRaw;

    setupContentDigest();
}
项目:irma_future_id    文件:PSSSignatureSpi.java   
protected PSSSignatureSpi(
    String name,
    AsymmetricBlockCipher signer,
    Digest digest)
{
    super(name);

    this.signer = signer;
    this.mgfDigest = digest;

    if (digest != null)
    {
        this.saltLength = digest.getDigestSize();
    }
    else
    {
        this.saltLength = 20;
    }

    this.isRaw = false;

    setupContentDigest();
}
项目:irma_future_id    文件:PSSSignatureSpi.java   
protected PSSSignatureSpi(
    String name,
    AsymmetricBlockCipher signer,
    Digest digest,
    boolean isRaw)
{
    super(name);

    this.signer = signer;
    this.mgfDigest = digest;

    if (digest != null)
    {
        this.saltLength = digest.getDigestSize();
    }
    else
    {
        this.saltLength = 20;
    }

    this.isRaw = isRaw;

    setupContentDigest();
}
项目:bc-java    文件:BcAsymmetricKeyWrapper.java   
public byte[] generateWrappedKey(GenericKey encryptionKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyEncryptionCipher = createAsymmetricWrapper(getAlgorithmIdentifier().getAlgorithm());

    CipherParameters params = publicKey;
    if (random != null)
    {
        params = new ParametersWithRandom(params, random);
    }

    try
    {
        byte[] keyEnc = OperatorUtils.getKeyBytes(encryptionKey);
        keyEncryptionCipher.init(true, publicKey);
        return keyEncryptionCipher.processBlock(keyEnc, 0, keyEnc.length);
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to encrypt contents key", e);
    }
}
项目:bc-java    文件:BcAsymmetricKeyUnwrapper.java   
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyCipher = createAsymmetricUnwrapper(this.getAlgorithmIdentifier().getAlgorithm());

    keyCipher.init(false, privateKey);
    try
    {
        byte[] key = keyCipher.processBlock(encryptedKey, 0, encryptedKey.length);

        if (encryptedKeyAlgorithm.getAlgorithm().equals(PKCSObjectIdentifiers.des_EDE3_CBC))
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
        else
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to recover secret key: " + e.getMessage(), e);
    }
}
项目:bc-java    文件:BcPublicKeyKeyEncryptionMethodGenerator.java   
protected byte[] encryptSessionInfo(PGPPublicKey pubKey, byte[] sessionInfo)
    throws PGPException
{
    try
    {
        AsymmetricBlockCipher c = BcImplProvider.createPublicKeyCipher(pubKey.getAlgorithm());

        AsymmetricKeyParameter key = keyConverter.getPublicKey(pubKey);

        if (random == null)
        {
            random = new SecureRandom();
        }

        c.init(true, new ParametersWithRandom(key, random));

        return c.processBlock(sessionInfo, 0, sessionInfo.length);
    }
    catch (InvalidCipherTextException e)
    {
        throw new PGPException("exception encrypting session info: " + e.getMessage(), e);
    }
}
项目:bc-java    文件:OAEPEncoding.java   
public OAEPEncoding(
    AsymmetricBlockCipher       cipher,
    Digest                      hash,
    Digest                      mgf1Hash,
    byte[]                      encodingParams)
{
    this.engine = cipher;
    this.mgf1Hash = mgf1Hash;
    this.defHash = new byte[hash.getDigestSize()];

    hash.reset();

    if (encodingParams != null)
    {
        hash.update(encodingParams, 0, encodingParams.length);
    }

    hash.doFinal(defHash, 0);
}
项目:bc-java    文件:PSSSigner.java   
public PSSSigner(
    AsymmetricBlockCipher   cipher,
    Digest                  contentDigest,
    Digest                  mgfDigest,
    int                     sLen,
    byte                    trailer)
{
    this.cipher = cipher;
    this.contentDigest = contentDigest;
    this.mgfDigest = mgfDigest;
    this.hLen = contentDigest.getDigestSize();
    this.mgfhLen = mgfDigest.getDigestSize();
    this.sLen = sLen;
    this.salt = new byte[sLen];
    this.mDash = new byte[8 + sLen + hLen];
    this.trailer = trailer;
}
项目:bc-java    文件:PSSSignatureSpi.java   
protected PSSSignatureSpi(
    AsymmetricBlockCipher signer,
    PSSParameterSpec baseParamSpec,
    boolean isRaw)
{
    this.signer = signer;
    this.originalSpec = baseParamSpec;

    if (baseParamSpec == null)
    {
        this.paramSpec = PSSParameterSpec.DEFAULT;
    }
    else
    {
        this.paramSpec = baseParamSpec;
    }

    this.mgfDigest = DigestFactory.getDigest(paramSpec.getDigestAlgorithm());
    this.saltLength = paramSpec.getSaltLength();
    this.trailer = getTrailer(paramSpec.getTrailerField());
    this.isRaw = isRaw;

    setupContentDigest();
}