AuthenticationHelper.java 2.04 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.commons.codec.binary.Base64
 *  org.apache.commons.codec.binary.StringUtils
 */
package com.day.cq.analytics.sitecatalyst.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;

public class AuthenticationHelper {
    @Deprecated
    public static String generateSharedSecret(String password) {
        throw new UnsupportedOperationException("This method is no longer supported.");
    }

    @Deprecated
    public static synchronized String generateApplicationKey(byte[] nonceValue, String key) throws Exception {
        throw new UnsupportedOperationException("This method is no longer supported.");
    }

    public static synchronized String getBase64Digest(byte[] nonce, byte[] created, byte[] password) {
        try {
            MessageDigest messageDigester = MessageDigest.getInstance("SHA-1");
            messageDigester.reset();
            messageDigester.update(nonce);
            messageDigester.update(created);
            messageDigester.update(password);
            return AuthenticationHelper.base64Encode(messageDigester.digest());
        }
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    public static synchronized String getBase64DigestKey(byte[] nonce, byte[] apiPass) {
        try {
            MessageDigest messageDigester = MessageDigest.getInstance("SHA-1");
            messageDigester.reset();
            messageDigester.update(nonce);
            messageDigester.update(apiPass);
            return AuthenticationHelper.base64Encode(messageDigester.digest());
        }
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

    public static String base64Encode(byte[] bytes) {
        return StringUtils.newStringUtf8((byte[])Base64.encodeBase64((byte[])bytes, (boolean)false));
    }
}