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


Java BouncyCastleProvider类代码示例

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


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

示例1: doEcDh

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
@Override
public final byte[] doEcDh(final Key privateKey,
		             final byte[] publicKey,
		             final EcCurve curveName) throws NoSuchAlgorithmException,
		                                             InvalidKeyException,
		                                             InvalidKeySpecException {

	if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
		Security.insertProviderAt(new BouncyCastleProvider(), 1);
	}
	KeyAgreement ka = null;
	try {
		ka = KeyAgreement.getInstance(ECDH, BouncyCastleProvider.PROVIDER_NAME);

	}
	catch (final NoSuchProviderException e) {
		ka = KeyAgreement.getInstance(ECDH);
	}
	ka.init(privateKey);
	ka.doPhase(loadEcPublicKey(publicKey, curveName), true);
	return ka.generateSecret();
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:23,代码来源:JseCryptoHelper.java

示例2: loadEcPublicKey

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
private static Key loadEcPublicKey(final byte [] pubKey,
                                      final EcCurve curveName) throws NoSuchAlgorithmException,
                                                                      InvalidKeySpecException {
    final ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(curveName.toString());
    KeyFactory kf;
	try {
		kf = KeyFactory.getInstance(ECDH, BouncyCastleProvider.PROVIDER_NAME);
	}
	catch (final NoSuchProviderException e) {
		kf = KeyFactory.getInstance(ECDH);
	}
    final ECNamedCurveSpec params = new ECNamedCurveSpec(curveName.toString(), spec.getCurve(), spec.getG(), spec.getN());
    final ECPoint point =  ECPointUtil.decodePoint(params.getCurve(), pubKey);
    final java.security.spec.ECPublicKeySpec pubKeySpec = new java.security.spec.ECPublicKeySpec(point, params);
    return kf.generatePublic(pubKeySpec);
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:17,代码来源:JseCryptoHelper.java

示例3: generateEcKeyPair

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
@Override
public KeyPair generateEcKeyPair(final EcCurve curveName) throws NoSuchAlgorithmException,
                                                                 InvalidAlgorithmParameterException {
	if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
		Security.addProvider(new BouncyCastleProvider());
	}
	KeyPairGenerator kpg;
	try {
		kpg = KeyPairGenerator.getInstance("EC", BouncyCastleProvider.PROVIDER_NAME); //$NON-NLS-1$
	}
	catch (final Exception e) {
		Logger.getLogger("es.gob.jmulticard").warning( //$NON-NLS-1$
			"No se ha podido obtener un generador de pares de claves de curva eliptica con SpongyCastle, se usara el generador por defecto: " + e //$NON-NLS-1$
		);
		kpg = KeyPairGenerator.getInstance("EC"); //$NON-NLS-1$
	}

	Logger.getLogger("es.gob.jmulticard").info( //$NON-NLS-1$
		"Seleccionado el siguiente generador de claves de curva eliptica: " + kpg.getClass().getName() //$NON-NLS-1$
	);

	final AlgorithmParameterSpec parameterSpec = new ECGenParameterSpec(curveName.toString());
	kpg.initialize(parameterSpec);
	return kpg.generateKeyPair();
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:26,代码来源:JseCryptoHelper.java

示例4: doEcDh

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
@Override
public byte[] doEcDh(final Key privateKey,
		             final byte[] publicKey,
		             final EcCurve curveName) throws NoSuchAlgorithmException,
		                                             InvalidKeyException,
		                                             InvalidKeySpecException {

	if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
		Security.addProvider(new BouncyCastleProvider());
	}
	KeyAgreement ka;
	try {
		ka = KeyAgreement.getInstance(ECDH, BouncyCastleProvider.PROVIDER_NAME);
	}
	catch (final NoSuchProviderException e) {
		ka = KeyAgreement.getInstance(ECDH);
	}
	ka.init(privateKey);
	ka.doPhase(loadEcPublicKey(publicKey, curveName), true);
	return ka.generateSecret();
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:22,代码来源:JseCryptoHelper.java

示例5: encrypt

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
public String encrypt(String input, RSAPublicKey publicKey) {

        if (input == null) {
            return null;
        }

        try {
            byte[] dataBytes = input.getBytes(CHARSET);
            Cipher cipher = Cipher.getInstance(ALGORITHM, new BouncyCastleProvider());
            cipher.init(Cipher.ENCRYPT_MODE, publicKey);
            return Base64.encodeToString(cipher.doFinal(dataBytes), BASE64_MODE);
        } catch (IllegalBlockSizeException |
                BadPaddingException |
                NoSuchAlgorithmException |
                NoSuchPaddingException |
                UnsupportedEncodingException |
                InvalidKeyException e) {
            Log.e("QlassifiedCrypto", String.format("Could not encrypt this string. Stacktrace: %s", e));
            return null;
        }
    }
 
开发者ID:Q42,项目名称:Qlassified-Android,代码行数:22,代码来源:QlassifiedCrypto.java

示例6: loadCertificate

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
protected ValidationResult loadCertificate(File keystoreFile, char[] keystorePassword, String alias) {
	Security.addProvider(new BouncyCastleProvider());
	
	ValidationResult result = new ValidationResult(13, ValidationResult.MessageSeverity.ERROR, R.string.error_unexpected);
	
	ValidationResult keystoreResult = loadKeystore(keystoreFile, keystorePassword);
	
	if (keystoreResult.resultCode() != 0) {
		result = keystoreResult;
	} else {
		try {
			if (keystore.containsAlias(alias)) {
				certificate = (X509Certificate) keystore.getCertificate(alias);
				
				//We just need to make sure that we can load these - we don't actually have to use them...
				result = new ValidationResult(0);
			}
		} catch (KeyStoreException e) {
			e.printStackTrace();
		}
	}
	
	return result;
}
 
开发者ID:Calsign,项目名称:APDE,代码行数:25,代码来源:ExportSignedPackage.java

示例7: createKeyStore

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
public static KeyStore createKeyStore( String keystorePath, char[] password)
    throws Exception
{
    KeyStore ks = null;
    if (keystorePath.toLowerCase().endsWith(".bks")) {
        ks = KeyStore.getInstance("bks", new BouncyCastleProvider());
    }
    else ks = new JksKeyStore();
    ks.load(null, password);

    return ks;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:13,代码来源:KeyStoreFileManager.java

示例8: AmCryptoProvider

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
/**
 * Asigna un proveedor criptográfico.
 */
public AmCryptoProvider() {
	Security.addProvider(new BouncyCastleProvider());
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:7,代码来源:AmCryptoProvider.java

示例9: generateEcKeyPair

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
@Override
public KeyPair generateEcKeyPair(final EcCurve curveName) throws NoSuchAlgorithmException,
                                                                 InvalidAlgorithmParameterException {


	if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
		Security.insertProviderAt(new BouncyCastleProvider(), 1);
	}
	KeyPairGenerator kpg;
	try {
		kpg = KeyPairGenerator.getInstance(ECDH, BouncyCastleProvider.PROVIDER_NAME);
	}
	catch (final Exception e) {
		Logger.getLogger("es.gob.jmulticard").warning( //$NON-NLS-1$
			"No se ha podido obtener un generador de pares de claves de curva eliptica con BouncyCastle, se usara el generador por defecto: " + e //$NON-NLS-1$
		);
		kpg = KeyPairGenerator.getInstance(ECDH);
	}

	Logger.getLogger("es.gob.jmulticard").info( //$NON-NLS-1$
		"Seleccionado el siguiente generador de claves de curva eliptica: " + kpg.getClass().getName() //$NON-NLS-1$
	);

	final AlgorithmParameterSpec parameterSpec = new ECGenParameterSpec(curveName.toString());
	kpg.initialize(parameterSpec);
	return kpg.generateKeyPair();
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:28,代码来源:JseCryptoHelper.java

示例10: encryptFile

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
public static boolean encryptFile(InputStream in, OutputStream out, File pubKeyFile,
                           boolean integrityCheck, Date fileDate,String filename){
    boolean status;
   try{
       PGPPublicKey encKey=MyPGPUtil.readPublicKey(new FileInputStream(pubKeyFile));
       Security.addProvider(new BouncyCastleProvider());

       PGPEncryptedDataGenerator cPk =
               new PGPEncryptedDataGenerator(
                       new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).
                               setWithIntegrityPacket(integrityCheck).
                               setSecureRandom(
                                       new SecureRandom()
                               )
               );

       cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(encKey));

       OutputStream                cOut = cPk.open(out, new byte[1 << 16]);

       PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(
               PGPCompressedData.UNCOMPRESSED);

       PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
       OutputStream pOut = lData.open(comData.open(cOut), PGPLiteralData.BINARY,filename ,fileDate, new byte[1 << 16]);
       PGPUtil.pipeDocumentFileContents(in,pOut, new byte[1 << 16].length);
       comData.close();

       cOut.close();
       Log.d(TAG,"file successfully encrypted");
       status=true;
   }catch (Exception ex){
       Log.d(TAG, "encryptFile: error in encrypting document file");
       ex.printStackTrace();
       status=false;
   }

    return status;
}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:40,代码来源:DocumentFileEncryption.java

示例11: encryptFile

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
@Override
public boolean encryptFile(File outputFile, File inputFile,
                         File pubKeyFile,Boolean integrityCheck
) throws Exception {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile));
    String fileName=inputFile.getPath();
    PGPPublicKey encKey=keyManagement.getPublicKey(pubKeyFile);
    Security.addProvider(new BouncyCastleProvider());

    PGPEncryptedDataGenerator cPk =
            new PGPEncryptedDataGenerator(
                    new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).
                            setWithIntegrityPacket(integrityCheck).
                            setSecureRandom(
                                    new SecureRandom()
                            )
            );

    cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(encKey));

    OutputStream                cOut = cPk.open(out, new byte[1 << 16]);

    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(
            PGPCompressedData.UNCOMPRESSED);

    PGPUtil.writeFileToLiteralData(comData.open(cOut), PGPLiteralData.BINARY, new File(fileName), new byte[1 << 16]);

    comData.close();

    cOut.close();
    Log.d("encrypt","file successfully encrypted");
    return true;
}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:34,代码来源:EncryptionManagement.java

示例12: initLocalSystem

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
private void initLocalSystem(final boolean noLocalFileSystemAccess) throws IOException {
  // install BC, if not already done
  if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
    Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
    // Security.insertProviderAt(new
    // org.bouncycastle.jce.provider.BouncyCastleProvider(),2);
  }
  // logger and config
  LOG.info("Tor implementation of silvertunnel-ng.org is starting up");
  // determine end of startup-Phase
  startupPhaseWithoutConnects = System.currentTimeMillis() + TorConfig.getStartupDelay() * 1000L;
  // init event-handler
}
 
开发者ID:B4dT0bi,项目名称:silvertunnel-ng,代码行数:14,代码来源:Tor.java

示例13: setUpClass

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception
{
	// install BC, if not already done
	if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null)
	{
		Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
	}
}
 
开发者ID:B4dT0bi,项目名称:silvertunnel-ng,代码行数:10,代码来源:DirectoryConsensusLocalTest.java

示例14: setUpClass

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
    // install BC, if not already done
    if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
        Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
    }
}
 
开发者ID:B4dT0bi,项目名称:silvertunnel-ng,代码行数:8,代码来源:AuthorityKeyCertificatesLocalTest.java

示例15: getPubKeyFromCurve

import org.spongycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
/**
 * Decode based on X, Y 32 byte integers
 * @param pubKey
 * @param curveName - Example secp256r1
 * @return
 * @throws InvalidKeySpecException
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 */
public static PublicKey getPubKeyFromCurve (byte[] pubKey, String curveName) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException {
 
 ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(curveName);
  KeyFactory kf = KeyFactory.getInstance("ECDSA", new BouncyCastleProvider());
  ECNamedCurveSpec params = new ECNamedCurveSpec(curveName, spec.getCurve(), spec.getG(), spec.getN());
  ECPoint point =  ECPointUtil.decodePoint(params.getCurve(), pubKey);
  ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params);
  ECPublicKey pk = (ECPublicKey) kf.generatePublic(pubKeySpec);
  return pk;
}
 
开发者ID:zsavvas,项目名称:ReCRED_FIDO_UAF_OIDC,代码行数:20,代码来源:KeyCodec.java


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