当前位置: 首页>>代码示例>>Java>>正文


Java PKCS1Encoding.processBlock方法代码示例

本文整理汇总了Java中org.bouncycastle.crypto.encodings.PKCS1Encoding.processBlock方法的典型用法代码示例。如果您正苦于以下问题:Java PKCS1Encoding.processBlock方法的具体用法?Java PKCS1Encoding.processBlock怎么用?Java PKCS1Encoding.processBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.crypto.encodings.PKCS1Encoding的用法示例。


在下文中一共展示了PKCS1Encoding.processBlock方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decryptPreMasterSecret

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
public byte[] decryptPreMasterSecret(byte[] encryptedPreMasterSecret)
    throws IOException
{

    PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
    encoding.init(false, new ParametersWithRandom(this.privateKey, context.getSecureRandom()));

    try
    {
        return encoding.processBlock(encryptedPreMasterSecret, 0,
            encryptedPreMasterSecret.length);
    }
    catch (InvalidCipherTextException e)
    {
        throw new TlsFatalAlert(AlertDescription.illegal_parameter);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:18,代码来源:DefaultTlsEncryptionCredentials.java

示例2: encryptKeyRSA

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
public static byte[] encryptKeyRSA(AKey encryptionKey, ASecretKey toBeEncrypted) throws Exception
{
	PKCS1Encoding rsa = new PKCS1Encoding(new RSAEngine());
	rsa.init(true, getCipherParameters(encryptionKey));
	
	byte[] k = toBeEncrypted.toByteArray();
	try
	{
		byte[] encrypted = rsa.processBlock(k, 0, k.length);
		return encrypted;
	}
	finally
	{
		Crypto.zero(k);
	}
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:17,代码来源:Crypto.java

示例3: verifySignature

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
/**
 * checks signature of PKCS1-padded SHA1 hash of the input
 * 
 * Hint: A different implementation of this method can be found in the svn history revision<=229. 
 * 
 * @param signature
 *            signature to check
 * @param signingKey
 *            public key from signing
 * @param input
 *            byte array, signature is made over
 * 
 * @return true, if the signature is correct
 * 
 */
public static boolean verifySignature(byte[] signature, RSAPublicKeyStructure signingKey, byte[] input) {
    byte[] hash = getDigest(input);

    try {
        RSAKeyParameters myRSAKeyParameters = new RSAKeyParameters(false,
                signingKey.getModulus(), signingKey.getPublicExponent());

        PKCS1Encoding pkcsAlg = new PKCS1Encoding(new RSAEngine());
        pkcsAlg.init(false, myRSAKeyParameters);

        byte[] decryptedSignature = pkcsAlg.processBlock(signature, 0, signature.length);

        return Encoding.arraysEqual(hash, decryptedSignature);

    } catch (Exception e) {
        log.log(Level.WARNING, "unexpected", e);
        return false;
    }
}
 
开发者ID:sirvaliance,项目名称:netlib,代码行数:35,代码来源:Encryption.java

示例4: generateClientKeyExchange

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
public byte[] generateClientKeyExchange() throws IOException
{
    /*
     * Choose a PremasterSecret and send it encrypted to the server
     */
    premasterSecret = new byte[48];
    handler.getRandom().nextBytes(premasterSecret);
    TlsUtils.writeVersion(premasterSecret, 0);

    PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
    encoding.init(true, new ParametersWithRandom(this.rsaServerPublicKey, handler.getRandom()));

    try
    {
        return encoding.processBlock(premasterSecret, 0, premasterSecret.length);
    }
    catch (InvalidCipherTextException e)
    {
        /*
         * This should never happen, only during decryption.
         */
        handler.failWithError(TlsProtocolHandler.AL_fatal, TlsProtocolHandler.AP_internal_error);
        return null; // Unreachable!
    }
}
 
开发者ID:coova,项目名称:jradius,代码行数:26,代码来源:TlsRSAKeyExchange.java

示例5: generateEncryptedPreMasterSecret

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
public static byte[] generateEncryptedPreMasterSecret(TlsContext context, RSAKeyParameters rsaServerPublicKey,
                                                      OutputStream output)
    throws IOException
{
    /*
     * Choose a PremasterSecret and send it encrypted to the server
     */
    byte[] premasterSecret = new byte[48];
    context.getSecureRandom().nextBytes(premasterSecret);
    TlsUtils.writeVersion(context.getClientVersion(), premasterSecret, 0);

    PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
    encoding.init(true, new ParametersWithRandom(rsaServerPublicKey, context.getSecureRandom()));

    try
    {
        byte[] encryptedPreMasterSecret = encoding.processBlock(premasterSecret, 0, premasterSecret.length);

        if (context.getServerVersion().isSSL())
        {
            // TODO Do any SSLv3 servers actually expect the length?
            output.write(encryptedPreMasterSecret);
        }
        else
        {
            TlsUtils.writeOpaque16(encryptedPreMasterSecret, output);
        }
    }
    catch (InvalidCipherTextException e)
    {
        /*
         * This should never happen, only during decryption.
         */
        throw new TlsFatalAlert(AlertDescription.internal_error);
    }

    return premasterSecret;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:39,代码来源:TlsRSAUtils.java

示例6: generateEncryptedPreMasterSecret

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
public static byte[] generateEncryptedPreMasterSecret(TlsContext context, RSAKeyParameters rsaServerPublicKey,
    OutputStream output) throws IOException
{
    /*
     * Choose a PremasterSecret and send it encrypted to the server
     */
    byte[] premasterSecret = new byte[48];
    context.getSecureRandom().nextBytes(premasterSecret);
    TlsUtils.writeVersion(context.getClientVersion(), premasterSecret, 0);

    PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
    encoding.init(true, new ParametersWithRandom(rsaServerPublicKey, context.getSecureRandom()));

    try
    {
        byte[] encryptedPreMasterSecret = encoding.processBlock(premasterSecret, 0, premasterSecret.length);

        if (TlsUtils.isSSL(context))
        {
            // TODO Do any SSLv3 servers actually expect the length?
            output.write(encryptedPreMasterSecret);
        }
        else
        {
            TlsUtils.writeOpaque16(encryptedPreMasterSecret, output);
        }
    }
    catch (InvalidCipherTextException e)
    {
        /*
         * This should never happen, only during decryption.
         */
        throw new TlsFatalAlert(AlertDescription.internal_error, e);
    }

    return premasterSecret;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:38,代码来源:TlsRSAUtils.java

示例7: decryptKeyRSA

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
public static ASecretKey decryptKeyRSA(AKey encryptionKey, byte[] b) throws Exception
{
	PKCS1Encoding rsa = new PKCS1Encoding(new RSAEngine());
	rsa.init(false, getCipherParameters(encryptionKey));
	
	byte[] decrypted = rsa.processBlock(b, 0, b.length);
	try
	{
		return new ASecretKey(decrypted);
	}
	finally
	{
		Crypto.zero(decrypted);
	}
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:16,代码来源:Crypto.java

示例8: generateEncryptedPreMasterSecret

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
public static byte[] generateEncryptedPreMasterSecret(TlsContext context, RSAKeyParameters rsaServerPublicKey,
    OutputStream output) throws IOException
{
    /*
     * Choose a PremasterSecret and send it encrypted to the server
     */
    byte[] premasterSecret = new byte[48];
    context.getSecureRandom().nextBytes(premasterSecret);
    TlsUtils.writeVersion(context.getClientVersion(), premasterSecret, 0);

    PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
    encoding.init(true, new ParametersWithRandom(rsaServerPublicKey, context.getSecureRandom()));

    try
    {
        byte[] encryptedPreMasterSecret = encoding.processBlock(premasterSecret, 0, premasterSecret.length);

        if (TlsUtils.isSSL(context))
        {
            // TODO Do any SSLv3 servers actually expect the length?
            output.write(encryptedPreMasterSecret);
        }
        else
        {
            TlsUtils.writeOpaque16(encryptedPreMasterSecret, output);
        }
    }
    catch (InvalidCipherTextException e)
    {
        /*
         * This should never happen, only during decryption.
         */
        throw new TlsFatalAlert(AlertDescription.internal_error);
    }

    return premasterSecret;
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:38,代码来源:TlsRSAUtils.java

示例9: signData

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
/**
 * sign some data using a private key and PKCS#1 v1.5 padding
 * 
 * @param data
 *            the data to be signed
 * @param signingKey
 *            the key to sign the data
 * @return a signature
 */
public static byte[] signData(byte[] data, RSAKeyParameters signingKey) {
    try {
        byte[] hash = Encryption.getDigest(data);
        PKCS1Encoding pkcs1 = new PKCS1Encoding(new RSAEngine());
        pkcs1.init(true, signingKey);
        return pkcs1.processBlock(hash, 0, hash.length);
    } catch (InvalidCipherTextException e) {
        log.log(Level.WARNING, "Common.signData(): " + e.getMessage(), e);
        return null;
    }
}
 
开发者ID:sirvaliance,项目名称:netlib,代码行数:21,代码来源:Encryption.java

示例10: safeDecryptPreMasterSecret

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入方法依赖的package包/类
public static byte[] safeDecryptPreMasterSecret(TlsContext context, RSAKeyParameters rsaServerPrivateKey,
    byte[] encryptedPreMasterSecret)
{
    /*
     * RFC 5246 7.4.7.1.
     */
    ProtocolVersion clientVersion = context.getClientVersion();

    // TODO Provide as configuration option?
    boolean versionNumberCheckDisabled = false;

    /*
     * Generate 48 random bytes we can use as a Pre-Master-Secret, if the
     * PKCS1 padding check should fail.
     */
    byte[] fallback = new byte[48];
    context.getSecureRandom().nextBytes(fallback);

    byte[] M = Arrays.clone(fallback);
    try
    {
        PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine(), fallback);
        encoding.init(false,
            new ParametersWithRandom(rsaServerPrivateKey, context.getSecureRandom()));

        M = encoding.processBlock(encryptedPreMasterSecret, 0, encryptedPreMasterSecret.length);
    }
    catch (Exception e)
    {
        /*
         * This should never happen since the decryption should never throw an exception
         * and return a random value instead.
         *
         * In any case, a TLS server MUST NOT generate an alert if processing an
         * RSA-encrypted premaster secret message fails, or the version number is not as
         * expected. Instead, it MUST continue the handshake with a randomly generated
         * premaster secret.
         */
    }

    /*
     * If ClientHello.client_version is TLS 1.1 or higher, server implementations MUST
     * check the version number [..].
     */
    if (versionNumberCheckDisabled && clientVersion.isEqualOrEarlierVersionOf(ProtocolVersion.TLSv10))
    {
        /*
         * If the version number is TLS 1.0 or earlier, server
         * implementations SHOULD check the version number, but MAY have a
         * configuration option to disable the check.
         *
         * So there is nothing to do here.
         */
    }
    else
    {
        /*
         * OK, we need to compare the version number in the decrypted Pre-Master-Secret with the
         * clientVersion received during the handshake. If they don't match, we replace the
         * decrypted Pre-Master-Secret with a random one.
         */
        int correct = (clientVersion.getMajorVersion() ^ (M[0] & 0xff))
            | (clientVersion.getMinorVersion() ^ (M[1] & 0xff));
        correct |= correct >> 1;
        correct |= correct >> 2;
        correct |= correct >> 4;
        int mask = ~((correct & 1) - 1);

        /*
         * mask will be all bits set to 0xff if the version number differed.
         */
        for (int i = 0; i < 48; i++)
        {
            M[i] = (byte)((M[i] & (~mask)) | (fallback[i] & mask));
        }
    }
    return M;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:79,代码来源:TlsRSAUtils.java


注:本文中的org.bouncycastle.crypto.encodings.PKCS1Encoding.processBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。