All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.structurizr.api.HmacAuthorizationHeader Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
package com.structurizr.api;

import java.util.Base64;

/**
 * Represents the header used for authorization purposes.
 */
final class HmacAuthorizationHeader {

    private String apiKey;
    private String hmac;

    HmacAuthorizationHeader(String apiKey, String hmac) {
        this.apiKey = apiKey;
        this.hmac = hmac;
    }

    String getApiKey() {
        return apiKey;
    }

    String getHmac() {
        return hmac;
    }

    String format() {
        return apiKey + ":" + Base64.getEncoder().encodeToString(hmac.getBytes());
    }

    static HmacAuthorizationHeader parse(String s) {
        String apiKey = s.split(":")[0];
        String hmac = new String(Base64.getDecoder().decode(s.split(":")[1]));

        return new HmacAuthorizationHeader(apiKey, hmac);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy