Search in sources :

Example 41 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project ovirt-engine by oVirt.

the class FiltersHelper method generateState.

public static String generateState() {
    byte[] s = new byte[8];
    secureRandom.nextBytes(s);
    return new Base64(0, new byte[0], true).encodeToString(s);
}
Also used : Base64(org.apache.commons.codec.binary.Base64)

Example 42 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project ovirt-engine by oVirt.

the class EngineEncryptionUtils method decrypt.

/**
 * Decrypt string.
 * @param source string to decrypt.
 * @return decrypted string.
 * @throws GeneralSecurityException
 * Please note that empty strings are not decrypted and are returned as-is.
 */
public static String decrypt(String source) throws GeneralSecurityException {
    if (source == null || source.length() == 0) {
        return source;
    } else {
        Cipher rsa = Cipher.getInstance("RSA");
        rsa.init(Cipher.DECRYPT_MODE, getPrivateKeyEntry().getPrivateKey());
        return new String(rsa.doFinal(new Base64().decode(source)), StandardCharsets.UTF_8);
    }
}
Also used : Base64(org.apache.commons.codec.binary.Base64) Cipher(javax.crypto.Cipher)

Example 43 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project ovirt-engine by oVirt.

the class EngineEncryptionUtils method encrypt.

/**
 * Encrypt string.
 * @param source string to encrypt.
 * @return encrypted string.
 * @throws GeneralSecurityException
 * Please note that empty strings are not encrypted and are returned as-is.
 */
public static String encrypt(String source) throws GeneralSecurityException {
    if (source == null || source.length() == 0) {
        return source;
    } else {
        Cipher rsa = Cipher.getInstance("RSA");
        rsa.init(Cipher.ENCRYPT_MODE, getCertificate().getPublicKey());
        return new Base64(0).encodeToString(rsa.doFinal(source.getBytes(StandardCharsets.UTF_8)));
    }
}
Also used : Base64(org.apache.commons.codec.binary.Base64) Cipher(javax.crypto.Cipher)

Example 44 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project ovirt-engine by oVirt.

the class Ticketing method generateOTP.

public static String generateOTP() {
    SecureRandom secr = new SecureRandom();
    byte[] arrRandom = new byte[9];
    secr.nextBytes(arrRandom);
    // encode password into Base64 text:
    return new Base64(0).encodeToString(arrRandom);
}
Also used : Base64(org.apache.commons.codec.binary.Base64) SecureRandom(java.security.SecureRandom)

Example 45 with Base64.encodeBase64String

use of org.apache.commons.codec.binary.Base64.encodeBase64String in project ovirt-engine by oVirt.

the class LoginOnBehalfCommand method createSession.

private String createSession(DbUser mappedUser, String authzName, ExtMap principalRecord) {
    directoryUtils.flatGroups(principalRecord);
    DbUser dbUser = directoryUtils.mapPrincipalRecordToDbUser(authzName, principalRecord);
    dbUser.setId(mappedUser.getId());
    String engineSessionId;
    byte[] s = new byte[64];
    new SecureRandom().nextBytes(s);
    engineSessionId = new Base64(0).encodeToString(s);
    sessionDataContainer.setUser(engineSessionId, dbUser);
    sessionDataContainer.refresh(engineSessionId);
    return engineSessionId;
}
Also used : Base64(org.apache.commons.codec.binary.Base64) SecureRandom(java.security.SecureRandom) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Aggregations

Base64 (org.apache.commons.codec.binary.Base64)149 IOException (java.io.IOException)33 Test (org.junit.Test)29 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 Base64.encodeBase64String (org.apache.commons.codec.binary.Base64.encodeBase64String)14 ByteArrayInputStream (java.io.ByteArrayInputStream)11 InputStream (java.io.InputStream)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)11 SecretKeySpec (javax.crypto.spec.SecretKeySpec)9 URL (java.net.URL)8 HashMap (java.util.HashMap)8 Cipher (javax.crypto.Cipher)8 File (java.io.File)7 MessageDigest (java.security.MessageDigest)7 Mac (javax.crypto.Mac)7 ServletException (javax.servlet.ServletException)7 FileNotFoundException (java.io.FileNotFoundException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 URLConnection (java.net.URLConnection)5