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


Java PKCS1Encoding类代码示例

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


PKCS1Encoding类属于org.bouncycastle.crypto.encodings包,在下文中一共展示了PKCS1Encoding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getRSADecryptCipher

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:chuckbuckethead,项目名称:cypher,代码行数:27,代码来源:RSAKey.java

示例4: getRSAEncryptCipher

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:chuckbuckethead,项目名称:cypher,代码行数:27,代码来源:RSAKey.java

示例5: 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

示例6: 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

示例7: createRSAImpl

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
protected AsymmetricBlockCipher createRSAImpl()
{
    /*
     * RFC 5264 7.4.7.1. Implementation note: It is now known that remote timing-based attacks
     * on TLS are possible, at least when the client and server are on the same LAN.
     * Accordingly, implementations that use static RSA keys MUST use RSA blinding or some other
     * anti-timing technique, as described in [TIMING].
     */
    return new PKCS1Encoding(new RSABlindedEngine());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:11,代码来源:TlsRSASigner.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 (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

示例9: 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

示例10: PKCS1v1_5Padding_PrivateOnly

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public PKCS1v1_5Padding_PrivateOnly()
{
    super(new PKCS1Encoding(new NativeRSAEngine()));
    try {
        engineSetMode("1");// private key only
    }
    catch(Exception e) {
        throw new RuntimeException( "bug", e );
    }
}
 
开发者ID:lookout,项目名称:fast-rsa-engine,代码行数:11,代码来源:FastCipherSpi.java

示例11: PKCS1v1_5Padding_PublicOnly

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public PKCS1v1_5Padding_PublicOnly()
{
    super(new PKCS1Encoding(new NativeRSAEngine()));
    try {
        engineSetMode("2");// public key only
    }
    catch(Exception e) {
        throw new RuntimeException( "bug", e );
    }
}
 
开发者ID:lookout,项目名称:fast-rsa-engine,代码行数:11,代码来源:FastCipherSpi.java

示例12: 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

示例13: 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

示例14: 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

示例15: calculateRawSignature

import org.bouncycastle.crypto.encodings.PKCS1Encoding; //导入依赖的package包/类
public byte[] calculateRawSignature(AsymmetricKeyParameter privateKey, byte[] md5andsha1)
    throws CryptoException
{
    Signer sig = new GenericSigner(new PKCS1Encoding(new RSABlindedEngine()), new NullDigest());
    sig.init(true, privateKey);
    sig.update(md5andsha1, 0, md5andsha1.length);
    return sig.generateSignature();
}
 
开发者ID:coova,项目名称:jradius,代码行数:9,代码来源:TlsRSASigner.java


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