Example usage for org.springframework.security.jwt.crypto.sign Signer sign

List of usage examples for org.springframework.security.jwt.crypto.sign Signer sign

Introduction

In this page you can find the example usage for org.springframework.security.jwt.crypto.sign Signer sign.

Prototype

byte[] sign(byte[] bytes);

Source Link

Usage

From source file:org.cloudfoundry.identity.uaa.util.UaaTokenUtils.java

public static String constructToken(Map<String, Object> header, Map<String, Object> claims, Signer signer) {
    byte[] headerJson = header == null ? new byte[0] : JsonUtils.writeValueAsBytes(header);
    byte[] claimsJson = claims == null ? new byte[0] : JsonUtils.writeValueAsBytes(claims);

    String headerBase64 = Base64.encodeBase64URLSafeString(headerJson);
    String claimsBase64 = Base64.encodeBase64URLSafeString(claimsJson);
    String headerAndClaims = headerBase64 + "." + claimsBase64;
    byte[] signature = signer.sign(headerAndClaims.getBytes());

    String signatureBase64 = Base64.encodeBase64URLSafeString(signature);

    return headerAndClaims + "." + signatureBase64;
}