⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sceprequestmessage.java

📁 一套JAVA的CA证书签发系统.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public PublicKey getRequestPublicKey() {        log.debug(">getRequestPublicKey()");        PublicKey ret = null;        try {            if (envData == null) {                init();                decrypt();            }            ret = super.getRequestPublicKey();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getRequestPublicKey()");        return ret;    }    /**     * Verifies signatures, popo etc on the request message. If verification fails the request     * should be considered invalid.     *     * @return True if verification was successful, false if it failed.     *     * @throws InvalidKeyException If the key used for verification is invalid.     * @throws NoSuchProviderException if there is an error with the Provider.     * @throws NoSuchAlgorithmException if the signature on the request is done with an unhandled     *         algorithm.     */    public boolean verify() {        log.debug(">verify()");        boolean ret = false;        try {            if (pkcs10 == null) {                init();                decrypt();            }            ret = super.verify();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<verify()");        return ret;    }    /**     * Returns the challenge password from the certificattion request.     *     * @return challenge password from certification request.     */    public String getPassword() {        log.debug(">getPassword()");        String ret = null;        try {            if (pkcs10 == null) {                init();                decrypt();            }            ret = super.getPassword();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getPassword()");        return ret;    }    /**     * Returns the string representation of the CN field from the DN of the certification request,     * to be used as username.     *     * @return username, which is the CN field from the subject DN in certification request.     */    public String getUsername() {        log.debug(">getUsername()");        String ret = null;        try {            if (pkcs10 == null) {                init();                decrypt();            }            ret = super.getUsername();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getUsername(): "+ret);        return ret;    }    /**     * Gets the issuer DN if contained in the request (the CA the request is targeted at).     *     * @return issuerDN of receiving CA or null.     */    public String getIssuerDN() {        log.debug(">getIssuerDN()");        String ret = null;        try {            if (envData == null) {                init();            }            ret = issuerDN;        } catch (IOException e) {            log.error("PKCS7 not inited!");        }        log.debug("<getIssuerDN(): "+ret);        return ret;    }    /**     * Gets the issuer DN (of CA cert) from IssuerAndSerialNumber when this is a CRL request.     *     * @return issuerDN of CA issuing CRL.     */    public String getCRLIssuerDN() {        log.debug(">getCRLIssuerDN()");        String ret = null;        try {            if (issuerAndSerno == null) {                init();                decrypt();            }            ret = CertTools.stringToBCDNString(issuerAndSerno.getName().toString());        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getCRLIssuerDN(): "+ret);        return ret;    }        /**     * Gets the number (of CA cert) from IssuerAndSerialNumber when this is a CRL request.     *     * @return serial number of CA certificate for CA issuing CRL.     */    public BigInteger getCRLSerialNo() {        log.debug(">getCRLSerialNo()");        BigInteger ret = null;        try {            if (issuerAndSerno == null) {                init();                decrypt();            }            ret = issuerAndSerno.getSerialNumber().getValue();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getCRLSerialNo(): "+ret);        return ret;    }    /**     * Returns the string representation of the subject DN from the certification request.     *     * @return subject DN from certification request.     */    public String getRequestDN() {        log.debug(">getRequestDN()");        String ret = null;        try {            if (pkcs10 == null) {                init();                decrypt();            }            ret = super.getRequestDN();        } catch (IOException e) {            log.error("PKCS7 not inited!");        } catch (GeneralSecurityException e) {            log.error("Error in PKCS7:", e);        } catch (CMSException e) {            log.error("Error in PKCS7:", e);        }        log.debug("<getRequestDN(): "+ret);        return ret;    }    /**     * indicates if this message needs recipients public and private key to verify, decrypt etc. If     * this returns true, setKeyInfo() should be called.     *     * @return True if public and private key is needed.     */    public boolean requireKeyInfo() {        return true;    }    /**     * Sets the public and private key needed to decrypt/verify the message. Must be set if     * requireKeyInfo() returns true.     *     * @param cert certificate containing the public key.     * @param key private key.     *     * @see #requireKeyInfo()     */    public void setKeyInfo(X509Certificate cert, PrivateKey key) {        // We don't need the public key         // this.cert = cert;        this.privateKey = key;    }    /**     * Returns an error number after an error has occured processing the request     *     * @return class specific error number     */    public int getErrorNo() {        return error;    }    /**     * Returns an error message after an error has occured processing the request     *     * @return class specific error message     */    public String getErrorText() {        return errorText;    }    /**     * Returns a senderNonce if present in the request     *     * @return senderNonce as a string of base64 encoded bytes     */    public String getSenderNonce() {        return senderNonce;    }    /**     * Returns a transaction identifier if present in the request     *     * @return transaction id     */    public String getTransactionId() {        return transactionId;    }    /**     * Returns requesters key info, key id or similar     *     * @return request key info     */    public byte[] getRequestKeyInfo() {        return requestKeyInfo;    }        /** Returns the type of SCEP message it is     *      * @return value as defined by SCEP_TYPE_PKCSREQ, SCEP_TYPE_GETCRL, SCEP_TYPE_GETCERT       */    public int getMessageType() {        return messageType;            }        //    // Private helper methods    //    private static boolean checkKeys(PublicKey pubK, PrivateKey privK) {        String in = "TheTopSecretTestString";        byte[] text = in.getBytes();        try {            Cipher cipher1 = Cipher.getInstance("RSA/ECB/PKCS1PADDING", "BC");            cipher1.init(Cipher.ENCRYPT_MODE, pubK);            byte[] textout = cipher1.doFinal(text);            Cipher cipher2 = Cipher.getInstance("RSA/ECB/PKCS1PADDING", "BC");            cipher2.init(Cipher.DECRYPT_MODE, privK);            byte[] out = cipher2.doFinal(textout);            log.debug("out=" + new String(out));            return in.equals(new String(out));        } catch (Exception e) {            return false;        }    }} // ScepRequestMessage

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -