List of usage examples for org.bouncycastle.util.encoders UrlBase64 encode
public static byte[] encode(byte[] data)
From source file:com.eucalyptus.auth.CredentialProvider.java
License:Open Source License
public static String getCertificateAlias(final String certPem) throws GeneralSecurityException { String certAlias = null;//from w w w . j a v a 2 s.c om EntityWrapper<X509Cert> db = Credentials.getEntityWrapper(); X509Cert certInfo = new X509Cert(); certInfo.setPemCertificate(new String(UrlBase64.encode(certPem.getBytes()))); try { certAlias = db.getUnique(certInfo).getAlias(); db.commit(); } catch (Throwable e) { db.rollback(); throw new GeneralSecurityException(e); } return certAlias; }
From source file:com.eucalyptus.auth.CredentialProvider.java
License:Open Source License
@SuppressWarnings("unchecked") public static String getUserName(X509Certificate cert) throws GeneralSecurityException { String certPem = new String(UrlBase64.encode(Hashes.getPemBytes(cert))); User searchUser = new User(); X509Cert searchCert = new X509Cert(); searchCert.setPemCertificate(certPem); searchUser.setIsEnabled(true);/*from www .j a v a 2 s .c om*/ EntityWrapper<User> db = Credentials.getEntityWrapper(); try { Session session = db.getSession(); Example qbeUser = Example.create(searchUser).enableLike(MatchMode.EXACT); Example qbeCert = Example.create(searchCert).enableLike(MatchMode.EXACT); List<User> users = (List<User>) session.createCriteria(User.class).add(qbeUser) .createCriteria("certificates").add(qbeCert).list(); if (users.size() > 1) { db.rollback(); throw new GeneralSecurityException("Multiple users with the same certificate."); } else if (users.size() < 1) { db.rollback(); new GeneralSecurityException("No user with the specified certificate."); } db.commit(); return users.get(0).getUserName(); } catch (HibernateException e) { db.rollback(); throw new GeneralSecurityException(e); } }
From source file:com.eucalyptus.auth.CredentialProvider.java
License:Open Source License
public static void addCertificate(final String userName, final String alias, final X509Certificate cert) throws GeneralSecurityException { String certPem = new String(UrlBase64.encode(Hashes.getPemBytes(cert))); EntityWrapper<User> db = Credentials.getEntityWrapper(); User u = null;/*w w w.j a v a2 s. c o m*/ try { u = db.getUnique(new User(userName)); X509Cert x509cert = new X509Cert(alias); x509cert.setPemCertificate(certPem); u.getCertificates().add(x509cert); db.commit(); } catch (EucalyptusCloudException e) { Credentials.LOG.error(e, e); Credentials.LOG.error("username=" + userName + " \nalias=" + alias + " \ncert=" + cert); db.rollback(); throw new GeneralSecurityException(e); } }
From source file:com.eucalyptus.auth.crypto.DefaultCryptoProvider.java
License:Open Source License
/** * Note that the output is not standard Base64. * * <p>The output has the following substitutions:</p> * * <ul>// w w w .j a v a 2 s .c o m * <li> + -> - </li> * <li> / -> _ </li> * <li> = -> . </li> * </ul> * * @see com.eucalyptus.crypto.CryptoProvider#getDigestBase64(java.lang.String, com.eucalyptus.crypto.Digest) */ @Override public String getDigestBase64(final String input, final Digest hash) { final byte[] inputBytes = input.getBytes(); final MessageDigest digest = hash.get(); digest.update(inputBytes); final byte[] digestBytes = digest.digest(); return new String(UrlBase64.encode(digestBytes)); }
From source file:com.eucalyptus.auth.crypto.StringCrypto.java
License:Open Source License
public byte[] encrypt(String password) throws GeneralSecurityException { Key pk = keystore.getCertificate(ALIAS).getPublicKey(); Cipher cipher = Cipher.getInstance(this.asymmetricFormat, this.provider); cipher.init(Cipher.ENCRYPT_MODE, pk); byte[] passwordEncrypted = cipher.doFinal(password.getBytes()); return UrlBase64.encode(passwordEncrypted); //return cat (VMwareBrokerProperties.ENCRYPTION_FORMAT.getBytes(), UrlBase64.encode(passwordEncrypted)); // prepend format }
From source file:com.eucalyptus.auth.crypto.StringCrypto.java
License:Open Source License
public byte[] encrypt(String string, String secret) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { final byte[] keyBytes = makeKey(secret); final SecretKey key = new SecretKeySpec(keyBytes, "DESede"); final IvParameterSpec iv = new IvParameterSpec(new byte[8]); final Cipher cipher = Cipher.getInstance(this.symmetricFormat); cipher.init(Cipher.ENCRYPT_MODE, key, iv); final byte[] stringEncrypted = cipher.doFinal(string.getBytes()); return UrlBase64.encode(stringEncrypted); }
From source file:com.eucalyptus.auth.util.Hashes.java
License:Open Source License
/** * TODO: Move this up in the dependency tree. * @param o/*from w ww . j a va 2s . c o m*/ * @return */ @Deprecated public static String base64encode(String input) { return new String(UrlBase64.encode(input.getBytes())); }
From source file:com.eucalyptus.auth.util.Hashes.java
License:Open Source License
public static String getRandom(int size) { SecureRandom random = Crypto.getSecureRandomSupplier().get(); byte[] randomBytes = new byte[size]; random.nextBytes(randomBytes);// w ww. j a v a 2 s .co m return new String(UrlBase64.encode(randomBytes)); }
From source file:com.eucalyptus.crypto.Crypto.java
License:Open Source License
public static String getRandom(int size) { SecureRandom random = getSecureRandomSupplier().get(); byte[] randomBytes = new byte[size]; random.nextBytes(randomBytes);/*from w ww . j a va 2 s .co m*/ return new String(UrlBase64.encode(randomBytes)); }
From source file:com.eucalyptus.crypto.StringCrypto.java
License:Open Source License
public byte[] encrypt(String password) throws GeneralSecurityException { Key pk = keystore.getCertificate(ALIAS).getPublicKey(); Cipher cipher = Cipher.getInstance(this.asymmetricFormat, this.provider); cipher.init(Cipher.ENCRYPT_MODE, pk, Crypto.getSecureRandomSupplier().get()); byte[] passwordEncrypted = cipher.doFinal(password.getBytes()); return UrlBase64.encode(passwordEncrypted); //return cat (VMwareBrokerProperties.ENCRYPTION_FORMAT.getBytes(), UrlBase64.encode(passwordEncrypted)); // prepend format }