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


Java OAEPEncoding类代码示例

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


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

示例1: BcRsaEncryptCipher

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
public BcRsaEncryptCipher(byte[] publicKey) {
    try {
        X509RsaPublicKey key = new X509RsaPublicKey(publicKey);
        RSAKeyParameters param = new RSAKeyParameters(false, key.getModulus(), key.getExponent());
        cipher = new OAEPEncoding(new RSAEngine(), new SHA1Digest());
        cipher.init(true, new ParametersWithRandom(param, RuntimeRandomProvider.INSTANCE));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:dsaved,项目名称:africhat-platform-0.1,代码行数:11,代码来源:BcRsaEncryptCipher.java

示例2: doOperation

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
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);
    }
}
 
开发者ID:d1x,项目名称:dxcrypto,代码行数:11,代码来源:BouncyCastleRSAEngine.java

示例3: initFromSpec

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
private void initFromSpec(
    OAEPParameterSpec pSpec)
    throws NoSuchPaddingException
{
    MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)pSpec.getMGFParameters();
    Digest digest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
    
    if (digest == null)
    {
        throw new NoSuchPaddingException("no match on OAEP constructor for digest algorithm: "+ mgfParams.getDigestAlgorithm());
    }

    cipher = new OAEPEncoding(new RSABlindedEngine(), digest, ((PSource.PSpecified)pSpec.getPSource()).getValue());
    paramSpec = pSpec;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:CipherSpi.java

示例4: initFromSpec

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
private void initFromSpec(
    OAEPParameterSpec pSpec) 
    throws NoSuchPaddingException
{
    MGF1ParameterSpec   mgfParams = (MGF1ParameterSpec)pSpec.getMGFParameters();
    Digest              digest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
    
    if (digest == null)
    {
        throw new NoSuchPaddingException("no match on OAEP constructor for digest algorithm: "+ mgfParams.getDigestAlgorithm());
    }

    cipher = new BufferedAsymmetricBlockCipher(new OAEPEncoding(new ElGamalEngine(), digest, ((PSource.PSpecified)pSpec.getPSource()).getValue()));        
    paramSpec = pSpec;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:CipherSpi.java

示例5: encDec

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
private void encDec(
    String label,
    RSAKeyParameters pubParameters,
    RSAKeyParameters privParameters,
    byte[] seed,
    byte[] input,
    byte[] output)
    throws InvalidCipherTextException
{
    AsymmetricBlockCipher cipher = new OAEPEncoding(new RSAEngine());

    cipher.init(true, new ParametersWithRandom(pubParameters, new VecRand(seed)));

    byte[]  out;

    out = cipher.processBlock(input, 0, input.length);

    for (int i = 0; i != output.length; i++)
    {
        if (out[i] != output[i])
        {
            fail(label + " failed encryption");
        }
    }

    cipher.init(false, privParameters);

    out = cipher.processBlock(output, 0, output.length);

    for (int i = 0; i != input.length; i++)
    {
        if (out[i] != input[i])
        {
            fail(label + " failed decoding");
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:38,代码来源:OAEPTest.java

示例6: initFromSpec

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
private void initFromSpec(OAEPParameterSpec pSpec)
    throws NoSuchPaddingException, NoSuchFieldException, IllegalAccessException
{
    MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)pSpec.getMGFParameters();
    Digest digest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());

    if (digest == null)
    {
        throw new NoSuchPaddingException("no match on OAEP constructor for digest algorithm: "+ mgfParams.getDigestAlgorithm());
    }

    cipher(new OAEPEncoding(new NativeRSAEngine(), digest, ((PSource.PSpecified)pSpec.getPSource()).getValue()));
    set( pSpec, "paramSpec" );
}
 
开发者ID:lookout,项目名称:fast-rsa-engine,代码行数:15,代码来源:FastCipherSpi.java

示例7: BcRsaCipher

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
public BcRsaCipher(byte[] publicKey, byte[] privateKey) {
    super(publicKey);

    try {
        PKS8RsaPrivateKey pks8RsaPrivateKey = new PKS8RsaPrivateKey(privateKey);
        AsymmetricKeyParameter keyParameter = new RSAKeyParameters(true, pks8RsaPrivateKey.getModulus(),
                pks8RsaPrivateKey.getExponent());
        cipher = new OAEPEncoding(new RSAEngine(), new SHA1Digest());
        cipher.init(false, new ParametersWithRandom(keyParameter, RuntimeRandomProvider.INSTANCE));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:dsaved,项目名称:africhat-platform-0.1,代码行数:14,代码来源:BcRsaCipher.java

示例8: asymEncrypt

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
/**
 * encrypt data with asymmetric key. create asymmetricla encrypted data:<br>
 * <ul>
 * <li>OAEP padding [42 bytes] (RSA-encrypted)
 * <li>Symmetric key [16 bytes]                   FIXME: we assume that we ALWAYS need this 
 * <li>First part of data [70 bytes]
 * <li>Second part of data [x-70 bytes] (Symmetrically encrypted)
 * <ul>
 * encrypt and store in result
 * 
 * @param pub
 * @param symmetricKey    AES key  
 * @param data
 *            to be encrypted, needs currently to be at least 70 bytes long
 * @return the first half of the key exchange, ready to be send to the other
 *         partner
 */
public static byte[] asymEncrypt(RSAPublicKey pub, byte[] symmetricKey, byte[] data) throws TorException {
    if (data == null) {
        throw new NullPointerException("can't encrypt NULL data");
    }
    if (data.length < 70) {
        throw new TorException("input array too short");
    }

    try {
        int encryptedBytes = 0;

        // initialize OAEP
        OAEPEncoding oaep = new OAEPEncoding(new RSAEngine());
        oaep.init(true, new RSAKeyParameters(false, pub.getModulus(), pub.getPublicExponent()));
        // apply RSA+OAEP
        encryptedBytes = oaep.getInputBlockSize();
        byte[] oaepInput = new byte[encryptedBytes];
        System.arraycopy(data, 0, oaepInput, 0, encryptedBytes);
        byte[] part1 = oaep.encodeBlock(oaepInput, 0, encryptedBytes);

        // initialize AES
        AESCounterMode aes = new AESCounterMode(true, symmetricKey);
        // apply AES
        byte[] aesInput = new byte[data.length - encryptedBytes];
        System.arraycopy(data, encryptedBytes, aesInput, 0, aesInput.length);
        byte part2[] = aes.processStream(aesInput);

        // replace unencrypted data
        byte[] result = new byte[part1.length + part2.length];
        System.arraycopy(part1, 0, result, 0, part1.length);
        System.arraycopy(part2, 0, result, part1.length, part2.length);

        return result;
    } catch (InvalidCipherTextException e) {
        log.severe("Node.asymEncrypt(): can't encrypt cipher text:" + e.getMessage());
        throw new TorException("InvalidCipherTextException:" + e.getMessage());
    }
}
 
开发者ID:sirvaliance,项目名称:netlib,代码行数:56,代码来源:Encryption.java

示例9: asymDecrypt

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
/**
 * decrypt data with asymmetric key. create asymmetrically encrypted data:<br>
 * <ul>
 * <li>OAEP padding [42 bytes] (RSA-encrypted)</li>
 * <li>Symmetric key [16 bytes]</li>
 * <li>First part of data [70 bytes]</li>
 * <li>Second part of data [x-70 bytes] (Symmetrically encrypted)</li>
 * </ul>
 * encrypt and store in result
 *
 * @param priv key to use for decryption
 * @param data to be decrypted, needs currently to be at least 70 bytes long
 * @return raw data
 */
public static byte[] asymDecrypt(final RSAPrivateKey priv, final byte[] data) throws TorException {

    if (data == null) {
        throw new NullPointerException("can't encrypt NULL data");
    }
    if (data.length < 70) {
        throw new TorException("input array too short");
    }

    try {
        int encryptedBytes = 0;

        // init OAEP
        final OAEPEncoding oaep = new OAEPEncoding(new RSAEngine());
        oaep.init(false, new RSAKeyParameters(true, priv.getModulus(), priv.getPrivateExponent()));
        // apply RSA+OAEP
        encryptedBytes = oaep.getInputBlockSize();
        final byte[] oaepInput = new byte[encryptedBytes];
        System.arraycopy(data, 0, oaepInput, 0, encryptedBytes);
        final byte[] part1 = oaep.decodeBlock(oaepInput, 0, encryptedBytes);

        // extract symmetric key
        final byte[] symmetricKey = new byte[16];
        System.arraycopy(part1, 0, symmetricKey, 0, 16);
        // init AES
        final AESCounterMode aes = new AESCounterMode(symmetricKey);
        // apply AES
        final byte[] aesInput = new byte[data.length - encryptedBytes];
        System.arraycopy(data, encryptedBytes, aesInput, 0, aesInput.length);
        final byte[] part2 = aes.processStream(aesInput);

        // replace unencrypted data
        final byte[] result = new byte[part1.length - 16 + part2.length];
        System.arraycopy(part1, 16, result, 0, part1.length - 16);
        System.arraycopy(part2, 0, result, part1.length - 16, part2.length);

        return result;

    } catch (final InvalidCipherTextException e) {
        logger.error("Encryption.asymDecrypt(): can't decrypt cipher text:" + e.getMessage());
        throw new TorException("Encryption.asymDecrypt(): InvalidCipherTextException:" + e.getMessage());
    }
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:58,代码来源:Encryption.java

示例10: OAEPPadding

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
public OAEPPadding()
{
    super(new OAEPEncoding(new RSABlindedEngine()));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:5,代码来源:CipherSpi.java

示例11: asymDecrypt

import org.bouncycastle.crypto.encodings.OAEPEncoding; //导入依赖的package包/类
/**
 * decrypt data with asymmetric key. create asymmetrically encrypted data:<br>
 * <ul>
 * <li>OAEP padding [42 bytes] (RSA-encrypted)
 * <li>Symmetric key [16 bytes]
 * <li>First part of data [70 bytes]
 * <li>Second part of data [x-70 bytes] (Symmetrically encrypted)
 * <ul>
 * encrypt and store in result
 * 
 * @param priv
 *            key to use for decryption
 * @param data
 *            to be decrypted, needs currently to be at least 70 bytes long
 * @return raw data
 */
public static byte[] asymDecrypt(RSAPrivateKey priv, byte[] data)
        throws TorException {

    if (data == null) {
        throw new NullPointerException("can't encrypt NULL data");
    }
    if (data.length < 70) {
        throw new TorException("input array too short");
    }

    try {
        int encryptedBytes = 0;

        // init OAEP
        OAEPEncoding oaep = new OAEPEncoding(new RSAEngine());
        oaep.init(false, new RSAKeyParameters(true, priv.getModulus(), priv.getPrivateExponent()));
        // apply RSA+OAEP
        encryptedBytes = oaep.getInputBlockSize();
        byte[] oaepInput = new byte[encryptedBytes];
        System.arraycopy(data, 0, oaepInput, 0, encryptedBytes);
        byte[] part1 = oaep.decodeBlock(oaepInput, 0, encryptedBytes);

        // extract symmetric key
        byte[] symmetricKey = new byte[16];
        System.arraycopy(part1, 0, symmetricKey, 0, 16);
        // init AES
        AESCounterMode aes = new AESCounterMode(true, symmetricKey);
        // apply AES
        byte[] aesInput = new byte[data.length - encryptedBytes];
        System.arraycopy(data, encryptedBytes, aesInput, 0, aesInput.length);
        byte part2[] = aes.processStream(aesInput);

        // replace unencrypted data
        byte[] result = new byte[part1.length - 16 + part2.length];
        System.arraycopy(part1, 16, result, 0, part1.length - 16);
        System.arraycopy(part2, 0, result, part1.length - 16, part2.length);

        return result;

    } catch (InvalidCipherTextException e) {
        log.severe("CommonEncryption.asymDecrypt(): can't decrypt cipher text:" + e.getMessage());
        throw new TorException("CommonEncryption.asymDecrypt(): InvalidCipherTextException:" + e.getMessage());
    }
}
 
开发者ID:sirvaliance,项目名称:netlib,代码行数:61,代码来源:Encryption.java


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