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

com.akeyless.api.utils.ApiUtils Maven / Gradle / Ivy

There is a newer version: 0.0.10
Show newest version
package com.akeyless.api.utils;

import com.akeyless.crypto.rsa.RsaMpcSign;
import com.akeyless.exceptions.AkeylessRuntimeException;
import org.apache.commons.codec.binary.Base64;

import java.math.BigInteger;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.util.ArrayList;
import java.util.Arrays;

public class ApiUtils {

    static public void validateFragmentedSignature(byte[] message,
                                                    ArrayList fragmentedSig,
                                                    RSAPrivateKey prvKey
    ) throws InvalidKeyException, NoSuchAlgorithmException, SignatureException {

        ArrayList signatures = new ArrayList<>(fragmentedSig.size());
        for (byte[] sig : fragmentedSig) {
            signatures.add(new BigInteger(1,sig));
        }

        byte[] finalTestSignature = RsaMpcSign.postSignPKCS1v15(signatures, prvKey.getModulus());

        Signature privateSignature = Signature.getInstance("SHA256withRSA");
        privateSignature.initSign(prvKey);
        privateSignature.update(message);

        byte[] standardSignature = privateSignature.sign();

        if(!Arrays.equals(standardSignature,finalTestSignature)) {
            throw new AkeylessRuntimeException("validation of fragmented signature failed");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy