Search in sources :

Example 1 with EncryptionResult

use of org.apache.knox.gateway.services.security.EncryptionResult in project knox by apache.

the class SecureQueryEncryptProcessor method encode.

private String encode(String string) throws UnsupportedEncodingException {
    EncryptionResult result = null;
    try {
        result = encryptor.encrypt(string);
    } catch (Exception e) {
        log.unableToEncryptValue(e);
    }
    string = Base64.encodeBase64URLSafeString(result.toByteAray());
    return string;
}
Also used : EncryptionResult(org.apache.knox.gateway.services.security.EncryptionResult) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with EncryptionResult

use of org.apache.knox.gateway.services.security.EncryptionResult in project knox by apache.

the class ConfigurableEncryptor method encrypt.

public EncryptionResult encrypt(String encrypt) throws Exception {
    byte[] bytes = encrypt.getBytes("UTF-8");
    EncryptionResult atom = encrypt(bytes);
    return atom;
}
Also used : EncryptionResult(org.apache.knox.gateway.services.security.EncryptionResult)

Example 3 with EncryptionResult

use of org.apache.knox.gateway.services.security.EncryptionResult in project knox by apache.

the class DecryptUriProcessor method decode.

private String decode(String string) throws UnsupportedEncodingException {
    byte[] bytes = Base64.decodeBase64(string);
    EncryptionResult result = EncryptionResult.fromByteArray(bytes);
    byte[] clear = cryptoService.decryptForCluster(clusterName, EncryptUriDescriptor.PASSWORD_ALIAS, result.cipher, result.iv, result.salt);
    if (clear != null) {
        return new String(clear, StandardCharsets.UTF_8);
    }
    return null;
}
Also used : EncryptionResult(org.apache.knox.gateway.services.security.EncryptionResult)

Example 4 with EncryptionResult

use of org.apache.knox.gateway.services.security.EncryptionResult in project knox by apache.

the class EncryptUriProcessor method encode.

private String encode(String string) throws UnsupportedEncodingException {
    EncryptionResult result = cryptoService.encryptForCluster(clusterName, EncryptUriDescriptor.PASSWORD_ALIAS, string.getBytes(StandardCharsets.UTF_8));
    string = Base64.encodeBase64URLSafeString(result.toByteAray());
    return string;
}
Also used : EncryptionResult(org.apache.knox.gateway.services.security.EncryptionResult)

Example 5 with EncryptionResult

use of org.apache.knox.gateway.services.security.EncryptionResult in project knox by apache.

the class CMFMasterService method persistMaster.

protected void persistMaster(char[] master, File masterFile) {
    try {
        EncryptionResult atom = encryptMaster(master);
        ArrayList<String> lines = new ArrayList<>();
        lines.add(MASTER_PERSISTENCE_TAG);
        String line = Base64.encodeBase64String((Base64.encodeBase64String(atom.salt) + "::" + Base64.encodeBase64String(atom.iv) + "::" + Base64.encodeBase64String(atom.cipher)).getBytes(StandardCharsets.UTF_8));
        lines.add(line);
        FileUtils.writeLines(masterFile, StandardCharsets.UTF_8.name(), lines);
        // restrict os permissions to only the user running this process
        chmod("600", masterFile);
    } catch (IOException e) {
        LOG.failedToPersistMasterSecret(e);
    }
}
Also used : EncryptionResult(org.apache.knox.gateway.services.security.EncryptionResult) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

EncryptionResult (org.apache.knox.gateway.services.security.EncryptionResult)9 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 TechnicalException (org.pac4j.core.exception.TechnicalException)2 SecureRandom (java.security.SecureRandom)1 ArrayList (java.util.ArrayList)1 Cipher (javax.crypto.Cipher)1 SecretKey (javax.crypto.SecretKey)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1