Java Code Examples for java.security.Signature#getAlgorithm()

The following examples show how to use java.security.Signature#getAlgorithm() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PKCS10.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create the signed certificate request.  This will later be
 * retrieved in either string or binary format.
 *
 * @param subject identifies the signer (by X.500 name).
 * @param signature private key and signing algorithm to use.
 * @exception IOException on errors.
 * @exception CertificateException on certificate handling errors.
 * @exception SignatureException on signature handling errors.
 */
public void encodeAndSign(X500Name subject, Signature signature)
throws CertificateException, IOException, SignatureException {
    DerOutputStream out, scratch;
    byte[]          certificateRequestInfo;
    byte[]          sig;

    if (encoded != null)
        throw new SignatureException("request is already signed");

    this.subject = subject;

    /*
     * Encode cert request info, wrap in a sequence for signing
     */
    scratch = new DerOutputStream();
    scratch.putInteger(BigInteger.ZERO);            // PKCS #10 v1.0
    subject.encode(scratch);                        // X.500 name
    scratch.write(subjectPublicKeyInfo.getEncoded()); // public key
    attributeSet.encode(scratch);

    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);      // wrap it!
    certificateRequestInfo = out.toByteArray();
    scratch = out;

    /*
     * Sign it ...
     */
    signature.update(certificateRequestInfo, 0,
            certificateRequestInfo.length);
    sig = signature.sign();
    sigAlg = signature.getAlgorithm();

    /*
     * Build guts of SIGNED macro
     */
    AlgorithmId algId = null;
    try {
        algId = AlgorithmId.get(signature.getAlgorithm());
    } catch (NoSuchAlgorithmException nsae) {
        throw new SignatureException(nsae);
    }
    algId.encode(scratch);     // sig algorithm
    scratch.putBitString(sig);                      // sig

    /*
     * Wrap those guts in a sequence
     */
    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);
    encoded = out.toByteArray();
}
 
Example 2
Source File: PKCS10.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create the signed certificate request.  This will later be
 * retrieved in either string or binary format.
 *
 * @param subject identifies the signer (by X.500 name).
 * @param signature private key and signing algorithm to use.
 * @exception IOException on errors.
 * @exception CertificateException on certificate handling errors.
 * @exception SignatureException on signature handling errors.
 */
public void encodeAndSign(X500Name subject, Signature signature)
throws CertificateException, IOException, SignatureException {
    DerOutputStream out, scratch;
    byte[]          certificateRequestInfo;
    byte[]          sig;

    if (encoded != null)
        throw new SignatureException("request is already signed");

    this.subject = subject;

    /*
     * Encode cert request info, wrap in a sequence for signing
     */
    scratch = new DerOutputStream();
    scratch.putInteger(BigInteger.ZERO);            // PKCS #10 v1.0
    subject.encode(scratch);                        // X.500 name
    scratch.write(subjectPublicKeyInfo.getEncoded()); // public key
    attributeSet.encode(scratch);

    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);      // wrap it!
    certificateRequestInfo = out.toByteArray();
    scratch = out;

    /*
     * Sign it ...
     */
    signature.update(certificateRequestInfo, 0,
            certificateRequestInfo.length);
    sig = signature.sign();
    sigAlg = signature.getAlgorithm();

    /*
     * Build guts of SIGNED macro
     */
    AlgorithmId algId = null;
    try {
        algId = AlgorithmId.get(signature.getAlgorithm());
    } catch (NoSuchAlgorithmException nsae) {
        throw new SignatureException(nsae);
    }
    algId.encode(scratch);     // sig algorithm
    scratch.putBitString(sig);                      // sig

    /*
     * Wrap those guts in a sequence
     */
    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);
    encoded = out.toByteArray();
}
 
Example 3
Source File: PKCS10.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create the signed certificate request.  This will later be
 * retrieved in either string or binary format.
 *
 * @param subject identifies the signer (by X.500 name).
 * @param signature private key and signing algorithm to use.
 * @exception IOException on errors.
 * @exception CertificateException on certificate handling errors.
 * @exception SignatureException on signature handling errors.
 */
public void encodeAndSign(X500Name subject, Signature signature)
throws CertificateException, IOException, SignatureException {
    DerOutputStream out, scratch;
    byte[]          certificateRequestInfo;
    byte[]          sig;

    if (encoded != null)
        throw new SignatureException("request is already signed");

    this.subject = subject;

    /*
     * Encode cert request info, wrap in a sequence for signing
     */
    scratch = new DerOutputStream();
    scratch.putInteger(BigInteger.ZERO);            // PKCS #10 v1.0
    subject.encode(scratch);                        // X.500 name
    scratch.write(subjectPublicKeyInfo.getEncoded()); // public key
    attributeSet.encode(scratch);

    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);      // wrap it!
    certificateRequestInfo = out.toByteArray();
    scratch = out;

    /*
     * Sign it ...
     */
    signature.update(certificateRequestInfo, 0,
            certificateRequestInfo.length);
    sig = signature.sign();
    sigAlg = signature.getAlgorithm();

    /*
     * Build guts of SIGNED macro
     */
    AlgorithmId algId = null;
    try {
        algId = AlgorithmId.get(signature.getAlgorithm());
    } catch (NoSuchAlgorithmException nsae) {
        throw new SignatureException(nsae);
    }
    algId.encode(scratch);     // sig algorithm
    scratch.putBitString(sig);                      // sig

    /*
     * Wrap those guts in a sequence
     */
    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);
    encoded = out.toByteArray();
}
 
Example 4
Source File: PKCS10.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create the signed certificate request.  This will later be
 * retrieved in either string or binary format.
 *
 * @param subject identifies the signer (by X.500 name).
 * @param signature private key and signing algorithm to use.
 * @exception IOException on errors.
 * @exception CertificateException on certificate handling errors.
 * @exception SignatureException on signature handling errors.
 */
public void encodeAndSign(X500Name subject, Signature signature)
throws CertificateException, IOException, SignatureException {
    DerOutputStream out, scratch;
    byte[]          certificateRequestInfo;
    byte[]          sig;

    if (encoded != null)
        throw new SignatureException("request is already signed");

    this.subject = subject;

    /*
     * Encode cert request info, wrap in a sequence for signing
     */
    scratch = new DerOutputStream();
    scratch.putInteger(BigInteger.ZERO);            // PKCS #10 v1.0
    subject.encode(scratch);                        // X.500 name
    scratch.write(subjectPublicKeyInfo.getEncoded()); // public key
    attributeSet.encode(scratch);

    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);      // wrap it!
    certificateRequestInfo = out.toByteArray();
    scratch = out;

    /*
     * Sign it ...
     */
    signature.update(certificateRequestInfo, 0,
            certificateRequestInfo.length);
    sig = signature.sign();
    sigAlg = signature.getAlgorithm();

    /*
     * Build guts of SIGNED macro
     */
    AlgorithmId algId = null;
    try {
        algId = AlgorithmId.get(signature.getAlgorithm());
    } catch (NoSuchAlgorithmException nsae) {
        throw new SignatureException(nsae);
    }
    algId.encode(scratch);     // sig algorithm
    scratch.putBitString(sig);                      // sig

    /*
     * Wrap those guts in a sequence
     */
    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);
    encoded = out.toByteArray();
}