package focusedCrawler.link.backlink;

import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;

public class MozAuthenticator {

    private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";

    /**
     * accessID The user's Access ID
     */
    private String accessID;

    /**
     * secretKey The user's Secret Key
     */
    private String secretKey;

    /**
     * expiresInterval The interval after which the authentication string
     * expires Default 300s
     */
    private long expiresInterval = 300;

    public MozAuthenticator() {

    }

    /**
     * Constructor to set all the variables
     * 
     * @param accessID
     * @param secretKey
     * @param expiresInterval
     */
    public MozAuthenticator(String accessID, String secretKey, long expiresInterval) {
        this.accessID = accessID;
        this.secretKey = secretKey;
        this.expiresInterval = expiresInterval;
    }

    /**
     * 
     * This method calculates the authentication String based on the user's
     * credentials.
     * 
     * Set the user credentials before calling this method
     * 
     * @return the authentication string
     * 
     * @see #setAccessID(String)
     * @see #setSecretKey(String)
     */
    public String getAuthenticationStr() {
        long expires = ((new Date()).getTime()) / 1000 + expiresInterval;

        String stringToSign = accessID + "\n" + expires;

        SecretKeySpec signingKey = new SecretKeySpec(secretKey.getBytes(), HMAC_SHA1_ALGORITHM);

        // get an hmac_sha1 Mac instance and initialize with the signing key
        Mac mac = null;
        try {
            mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
            mac.init(signingKey);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return "";
        } catch (InvalidKeyException e) {
            e.printStackTrace();
            return "";
        }

        // compute the hmac on input data bytes
        byte[] rawHmac = mac.doFinal(stringToSign.getBytes());

        // base64-encode the hmac
        @SuppressWarnings("deprecation")
        String urlSafeSignature = URLEncoder.encode(EncodeBase64(rawHmac));

        String authenticationStr = "AccessID=" + accessID + "&Expires=" + expires + "&Signature="
                + urlSafeSignature;

        return authenticationStr;
    }

    /**
     * Encodes the rawdata in Base64 format
     * 
     * @param rawData
     * @return
     */
    public String EncodeBase64(byte[] rawData) {
        return DatatypeConverter.printBase64Binary(rawData);
    }

    /**
     * @return the accessID
     */
    public String getAccessID() {
        return accessID;
    }

    /**
     * @param accessID
     *            the accessID to set
     */
    public void setAccessID(String accessID) {
        this.accessID = accessID;
    }

    /**
     * @return the secretKey
     */
    public String getSecretKey() {
        return secretKey;
    }

    /**
     * @param secretKey
     *            the secretKey to set
     */
    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    /**
     * @return the expiresInterval
     */
    public long getExpiresInterval() {
        return expiresInterval;
    }

    /**
     * @param expiresInterval
     *            the expiresInterval to set
     */
    public void setExpiresInterval(long expiresInterval) {
        this.expiresInterval = expiresInterval;
    }

}
@@ -141,32 +141,57 @@
 rithmException;%0A
+import java.util.Base64;%0A
 import java.util
@@ -266,49 +266,8 @@
 pec;
-%0Aimport javax.xml.bind.DatatypeConverter;
 %0A%0Apu
@@ -696,48 +696,8 @@
 0;%0A%0A
-    public MozAuthenticator() %7B%0A%0A    %7D%0A%0A
     
@@ -2290,17 +2290,17 @@
 .encode(
-E
+e
 ncodeBas
@@ -2601,29 +2601,30 @@
 */%0A    p
-ublic
+rivate
  String 
 EncodeBa
@@ -2615,17 +2615,17 @@
  String 
-E
+e
 ncodeBas
@@ -2665,43 +2665,42 @@
 urn 
-DatatypeConverter.printBase64Binary
+Base64.getEncoder().encodeToString
 (raw

Remove use of javax.xml.bind for compatibility with Java 11