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);
}
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);
}
}
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)));
}
}
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);
}
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;
}
Aggregations