List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider
public BouncyCastleProvider()
From source file:com.facebook.delegatedrecovery.DelegatedRecoveryConfiguration.java
License:Open Source License
/** * Turn the JSON public key array from a configuration into a set of usable * public keys for ECDSA on secp256r1//w w w . ja v a2s.c om * * @param array The JSON public key array * @return array of public keys decoded from the JSON array of base64 encoded * strings */ protected static ECPublicKey[] keysFromJsonArray(final JsonArray array) { try { final ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec("prime256v1"); final KeyFactory kf = KeyFactory.getInstance("EC", new BouncyCastleProvider()); final ECNamedCurveSpec params = new ECNamedCurveSpec("prime256v1", spec.getCurve(), spec.getG(), spec.getN()); final ArrayList<ECPublicKey> pubKeys = new ArrayList<ECPublicKey>(array.size()); for (int i = 0; i < array.size(); i++) { final String b64 = array.getString(i); final byte[] pubKeyAsn1 = Base64.getDecoder().decode(b64); final byte[] pubKey = new byte[pubKeyAsn1.length - PEM_ASN1_PREFIX.length]; // trim // PEM // ASN.1 // prefix System.arraycopy(pubKeyAsn1, PEM_ASN1_PREFIX.length, pubKey, 0, pubKey.length); final ECPoint point = ECPointUtil.decodePoint(params.getCurve(), pubKey); final ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params); try { final ECPublicKey pk = (ECPublicKey) kf.generatePublic(pubKeySpec); pubKeys.add(pk); } catch (InvalidKeySpecException e) { System.err.println("InvalidKeySpecException while processing " + b64); } } return pubKeys.toArray(new ECPublicKey[pubKeys.size()]); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); System.err.println("Unable to initialize ECDSA key factor for prime256v1. Cannot continue."); System.exit(1); return null; // unreachable but Eclipse complier wants me to return // something. :P } }
From source file:com.fitpay.android.Steps.java
protected Steps() { SecurityProvider.getInstance().setProvider(new BouncyCastleProvider()); userName = TestUtils.getRandomLengthString(5, 10) + "@" + TestUtils.getRandomLengthString(5, 10) + "." + TestUtils.getRandomLengthString(4, 10); password = TestUtils.getRandomLengthNumber(4, 4); }
From source file:com.fitpay.android.TestActions.java
@BeforeClass public static void init() { FPLog.clean(); //in tests only one log impl should be used FPLog.addLogImpl(new FPLog.ILog() { @Override//ww w. ja v a2s .c om public void d(String tag, String text) { System.out.println(tag + " DEBUG (" + Thread.currentThread().getName() + "): " + text); } @Override public void i(String tag, String text) { System.out.println(tag + " INFO(" + Thread.currentThread().getName() + "): " + text); } @Override public void w(String tag, String text) { System.out.println(tag + " WARN(" + Thread.currentThread().getName() + "): " + text); } @Override public void e(String tag, Throwable throwable) { System.out.println(tag + " ERROR (" + Thread.currentThread().getName() + "): " + tag); if (throwable != null) { throwable.printStackTrace(); } } @Override public int logLevel() { return FPLog.DEBUG; } }); FPLog.setShowHTTPLogs(false); SecurityProvider.getInstance().setProvider(new BouncyCastleProvider()); ApiManager.init(TestConstants.getConfig()); RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() { @Override public Scheduler getMainThreadScheduler() { return Schedulers.immediate(); } }); RxJavaHooks.setOnIOScheduler(scheduler -> Schedulers.immediate()); RxJavaHooks.setOnComputationScheduler(scheduler -> Schedulers.immediate()); RxJavaHooks.setOnNewThreadScheduler(scheduler -> Schedulers.immediate()); }
From source file:com.formkiq.core.service.crypto.KeyGenerator.java
License:Apache License
/** * Get Signer {@link KeyPair}./*from w ww .j a va2 s . c om*/ * @param keys {@link KeyPair} * @return {@link ContentSigner} */ private ContentSigner getSigner(final KeyPair keys) { try { return new JcaContentSignerBuilder(SIGNATURE_ALGORITHM).setProvider(new BouncyCastleProvider()) .build(keys.getPrivate()); } catch (OperatorCreationException e) { throw new RuntimeException(e); } }
From source file:com.FT_JSSH.SSHExec.java
License:Apache License
public Boolean Connect() { Boolean ret = true;//from w ww. ja va 2 s . c om // if in sim mode - sleep and return true if (m_Params.getSimulationMode()) { MiscUtils.Sleep(2000); return true; } m_SSHClient = new SSHClient(); try { // if there is a global key and the host does no override - use the global key // otherwise see if there is a host specific key and use it if found. // The key supercedes username and password File sshKeyFile = m_Params.getSshKeyFile(m_HostIndex); String password = m_Params.getPassword(m_HostIndex); String username = m_Params.getUserName(m_HostIndex); Boolean useGroupCreds = username.isEmpty(); /* the host creds supercede the group * only use group creds if host creds are invalid. * Allow empty passwords */ if (useGroupCreds) { sshKeyFile = m_Params.GetHostGroupSshKeyFile(); password = m_Params.GetHostGroupPassword(); username = m_Params.GetHostGroupUserName(); } // now that we have valid creds - // does not do server authentication! potentially dangerous AppLog.LogIt("JSSHExec #" + Integer.toString(m_HostIndex) + ": Connecting to host " + m_Params.getHostAddr(m_HostIndex), AppLog.LOG_LEVEL_INFO, AppLog.LOGFLAGS_ALL); m_SSHClient.addHostKeyVerifier(new PromiscuousVerifier()); m_SSHClient.connect(m_Params.getHostAddr(m_HostIndex)); // if we have ssh key - use it, otherwise use password if (sshKeyFile != null) { //Bouncy castle provider to read PEM keys Security.addProvider(new BouncyCastleProvider()); PKCS8KeyFile keyFile = new PKCS8KeyFile(); keyFile.init(sshKeyFile); m_SSHClient.authPublickey(username, keyFile); } else { m_SSHClient.authPassword(username, password); } m_Session = m_SSHClient.startSession(); } catch (Exception err) { ret = false; m_ResultString = "Failed to connect to host " + err.getMessage(); Cleanup(false); } return ret; }
From source file:com.geekcommune.identity.EncryptionUtil.java
License:Open Source License
private EncryptionUtil() { Security.addProvider(new BouncyCastleProvider()); PGPUtil.setDefaultProvider("BC"); }
From source file:com.ginema.crypto.encryption.PGPEncryption.java
License:Apache License
public static byte[] encrypt(byte[] original, InputStream pubKey) throws Exception { Security.addProvider(new BouncyCastleProvider()); return _doEncrypt(original, readPublicKey(pubKey), null, true, true); }
From source file:com.ginema.crypto.encryption.PGPKeyPairGenerator.java
License:Apache License
public static void main(String[] args) throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC"); kpg.initialize(1024);//from w w w . j av a 2 s. co m KeyPair kp = kpg.generateKeyPair(); if (args.length < 2) { System.out.println("RSAKeyPairGenerator [-a] identity passPhrase"); System.exit(0); } if (args[0].equals("-a")) { if (args.length < 3) { System.out.println("RSAKeyPairGenerator [-a] identity passPhrase"); System.exit(0); } FileOutputStream out1 = new FileOutputStream("secret.asc"); FileOutputStream out2 = new FileOutputStream("pub.asc"); exportKeyPair(out1, out2, kp.getPublic(), kp.getPrivate(), args[1], args[2].toCharArray(), true); } else { FileOutputStream out1 = new FileOutputStream("secret.bpg"); FileOutputStream out2 = new FileOutputStream("pub.bpg"); exportKeyPair(out1, out2, kp.getPublic(), kp.getPrivate(), args[0], args[1].toCharArray(), false); } }
From source file:com.github.adanac.framework.sso.common.util.Base64Util.java
License:Apache License
/** * BASE64 encrypt/*from w w w. ja v a2 s.c om*/ * * @param key * @return * @throws Exception */ public static String encryptBASE64(byte[] key) throws Exception { Security.addProvider(new BouncyCastleProvider()); byte[] b = UrlBase64.encode(key); return new String(b, SSOConfig.getEncoding()); }
From source file:com.github.adanac.framework.sso.common.util.Base64Util.java
License:Apache License
/** * BASE64 decrypt/* ww w .ja v a 2 s .com*/ * * @param key * @return * @throws Exception */ public static byte[] decryptBASE64(String key) throws Exception { Security.addProvider(new BouncyCastleProvider()); return UrlBase64.decode(key.getBytes(SSOConfig.getEncoding())); }