throws IOException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException
throws IOException, NoSuchAlgorithmException, InvalidKeyException, SignatureException
    static byte[] calculateSignature(        DERObjectIdentifier sigOid,        String              sigName,        String              provider,        PrivateKey          key,        SecureRandom        random,        ASN1Encodable       object)        throws IOException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException    {        Signature sig;        if (sigOid == null)        {            throw new IllegalStateException("no signature algorithm specified");        }        try        {            sig = X509Util.getSignatureInstance(sigOid.getId(), provider);        }        catch (NoSuchAlgorithmException ex)        {            sig = X509Util.getSignatureInstance(sigName, provider);        }        if (random != null)        {            sig.initSign(key); // can't handle random in JDK 1.1        }        else        {            sig.initSign(key);        }        sig.update(object.getEncoded(ASN1Encodable.DER));        return sig.sign();    }