當前位置: 首頁>>代碼示例>>Java>>正文


Java PrivateKey.getAlgorithm方法代碼示例

本文整理匯總了Java中java.security.PrivateKey.getAlgorithm方法的典型用法代碼示例。如果您正苦於以下問題:Java PrivateKey.getAlgorithm方法的具體用法?Java PrivateKey.getAlgorithm怎麽用?Java PrivateKey.getAlgorithm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.PrivateKey的用法示例。


在下文中一共展示了PrivateKey.getAlgorithm方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ECKey

import java.security.PrivateKey; //導入方法依賴的package包/類
/**
 * Pair a private key with a public EC point.
 *
 * All private key operations will use the provider.
 */
public ECKey(Provider provider, @Nullable PrivateKey privKey, ECPoint pub) {
    this.provider = provider;

    if (privKey == null || isECPrivateKey(privKey)) {
        this.privKey = privKey;
    } else {
        throw new IllegalArgumentException(
            "Expected EC private key, given a private key object with class " +
            privKey.getClass().toString() +
            " and algorithm " + privKey.getAlgorithm());
    }

    if (pub == null) {
        throw new IllegalArgumentException("Public key may not be null");
    } else {
        this.pub = pub;
    }
}
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:24,代碼來源:ECKey.java

示例2: engineInitSign

import java.security.PrivateKey; //導入方法依賴的package包/類
protected void engineInitSign(PrivateKey privateKey, SecureRandom random)
        throws InvalidKeyException {
    if (!(privateKey instanceof P11PrivateKey)) {
        throw new InvalidKeyException("privateKey is not instanceof "
                + P11PrivateKey.class.getName());
    }

    String algo = privateKey.getAlgorithm();
    if (!"RSA".equals(algo)) {
        throw new InvalidKeyException("privateKey is not an RSA private key: " + algo);
    }

    this.signingKey = (P11PrivateKey) privateKey;

    pss = new org.bouncycastle.crypto.signers.PSSSigner(signer, contentDigest, mgfDigest,
            saltLength, trailer);

    P11RSAKeyParameter p11KeyParam = P11RSAKeyParameter.getInstance(
            signingKey.p11CryptService(), signingKey.identityId());
    if (random == null) {
        pss.init(true, p11KeyParam);
    } else {
        pss.init(true, new ParametersWithRandom(p11KeyParam, random));
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:26,代碼來源:P11RSAPSSSignatureSpi.java

示例3: ECKey

import java.security.PrivateKey; //導入方法依賴的package包/類
/**
 * Pair a private key with a public EC point.
 *
 * All private key operations will use the provider.
 */
public ECKey(Provider provider, @Nullable PrivateKey privKey, ECPoint pub) {
  this.provider = provider;

  if (privKey == null || isECPrivateKey(privKey)) {
    this.privKey = privKey;
  } else {
    throw new IllegalArgumentException(
        "Expected EC private key, given a private key object with class "
            + privKey.getClass()
            + " and algorithm "
            + privKey.getAlgorithm());
  }

  if (pub == null) {
    throw new IllegalArgumentException("Public key may not be null");
  } else {
    this.pub = pub;
  }
}
 
開發者ID:Aptoide,項目名稱:AppCoins-ethereumj,代碼行數:25,代碼來源:ECKey.java

示例4: getPrivateKeyType

import java.security.PrivateKey; //導入方法依賴的package包/類
/**
 * Return the type of a given PrivateKey object. This is an integer
 * that maps to one of the values defined by org.chromium.net.PrivateKeyType,
 * which is itself auto-generated from net/android/private_key_type_list.h
 * @param privateKey The PrivateKey handle
 * @return key type, or PrivateKeyType.INVALID if unknown.
 */
@CalledByNative
private static int getPrivateKeyType(PrivateKey privateKey) {
    String keyAlgorithm = privateKey.getAlgorithm();
    if ("RSA".equalsIgnoreCase(keyAlgorithm)) {
        return PrivateKeyType.RSA;
    } else if ("EC".equalsIgnoreCase(keyAlgorithm)) {
        return PrivateKeyType.ECDSA;
    } else {
        return PrivateKeyType.INVALID;
    }
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:19,代碼來源:AndroidKeyStore.java

示例5: engineInitSign

import java.security.PrivateKey; //導入方法依賴的package包/類
@Override
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
    if (!(privateKey instanceof P11PrivateKey)) {
        throw new InvalidKeyException("privateKey is not instanceof "
                + P11PrivateKey.class.getName());
    }

    String algo = privateKey.getAlgorithm();
    if (!"RSA".equals(algo)) {
        throw new InvalidKeyException("privateKey is not an RSA private key: " + algo);
    }

    digest.reset();
    this.signingKey = (P11PrivateKey) privateKey;
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:16,代碼來源:P11RSADigestSignatureSpi.java

示例6: matchKeyPair

import java.security.PrivateKey; //導入方法依賴的package包/類
/**
 * Compare the supplied public and private keys, and determine if they correspond to the same key pair.
 * 
 * @param pubKey the public key
 * @param privKey the private key
 * @return true if the public and private are from the same key pair, false if not
 * @throws SecurityException if the keys can not be evaluated, or if the key algorithm is unsupported or unknown
 */
public static boolean matchKeyPair(PublicKey pubKey, PrivateKey privKey) throws SecurityException {
    Logger log = getLogger();
    // This approach attempts to match the keys by signing and then validating some known data.

    if (pubKey == null || privKey == null) {
        throw new SecurityException("Either public or private key was null");
    }

    // Need to dynamically determine the JCA signature algorithm ID to use from the key algorithm.
    // Don't currently have a direct mapping, so have to map to XML Signature algorithm URI first,
    // then map that to JCA algorithm ID.
    SecurityConfiguration secConfig = Configuration.getGlobalSecurityConfiguration();
    if (secConfig == null) {
        throw new SecurityException("Global security configuration was null, could not resolve signing algorithm");
    }
    String algoURI = secConfig.getSignatureAlgorithmURI(privKey.getAlgorithm());
    if (algoURI == null) {
        throw new SecurityException("Can't determine algorithm URI from key algorithm: " + privKey.getAlgorithm());
    }
    String jcaAlgoID = getAlgorithmIDFromURI(algoURI);
    if (jcaAlgoID == null) {
        throw new SecurityException("Can't determine JCA algorithm ID from algorithm URI: " + algoURI);
    }

    if (log.isDebugEnabled()) {
        log.debug("Attempting to match key pair containing key algorithms public '{}' private '{}', "
                + "using JCA signature algorithm '{}'", new Object[] { pubKey.getAlgorithm(),
                privKey.getAlgorithm(), jcaAlgoID, });
    }

    byte[] data = "This is the data to sign".getBytes();
    byte[] signature = SigningUtil.sign(privKey, jcaAlgoID, data);
    return SigningUtil.verify(pubKey, jcaAlgoID, signature, data);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:43,代碼來源:SecurityHelper.java

示例7: sign

import java.security.PrivateKey; //導入方法依賴的package包/類
private static void sign(Provider p, PrivateKey privateKey,
        PublicKey publicKey) throws Exception {
    String keyAlg = privateKey.getAlgorithm();
    String alg;
    switch (keyAlg) {
        case "RSA":
            alg = "SHA1withRSA";
            break;
        case "DSA":
            alg = "SHA1withDSA";
            break;
        case "EC":
            alg = "SHA1withECDSA";
            break;
        default:
            throw new Exception("Unknown algorithm " + keyAlg);
    }
    Signature s = Signature.getInstance(alg, p);
    s.initSign(privateKey);
    s.update(DATA);
    byte[] sig = s.sign();

    s.initVerify(publicKey);
    s.update(DATA);
    if (s.verify(sig) == false) {
        throw new Exception("Signature did not verify");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:AddPrivateKey.java

示例8: signAlias

import java.security.PrivateKey; //導入方法依賴的package包/類
private static int signAlias(int testnum, String alias) throws Exception {

        if (ks == null) {
            ks = KeyStore.getInstance(KS_TYPE, provider);
            ks.load(null, tokenPwd);
        }

        if (alias == null) {
            Enumeration enu = ks.aliases();
            if (enu.hasMoreElements()) {
                alias = (String)enu.nextElement();
            }
        }

        PrivateKey pkey = (PrivateKey)ks.getKey(alias, null);
        if ("RSA".equals(pkey.getAlgorithm())) {
            System.out.println("got [" + alias + "] signing key: " + pkey);
        } else {
            throw new SecurityException
                ("expected RSA, got " + pkey.getAlgorithm());
        }

        Signature s = Signature.getInstance("MD5WithRSA", ks.getProvider());
        s.initSign(pkey);
        System.out.println("initialized signature object with key");
        s.update("hello".getBytes());
        System.out.println("signature object updated with [hello] bytes");

        byte[] signed = s.sign();
        System.out.println("received signature " + signed.length +
                        " bytes in length");

        Signature v = Signature.getInstance("MD5WithRSA", ks.getProvider());
        v.initVerify(ks.getCertificate(alias));
        v.update("hello".getBytes());
        v.verify(signed);
        System.out.println("signature verified");
        System.out.println("test " + testnum++ + " passed");

        return testnum;
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:42,代碼來源:Basic.java


注:本文中的java.security.PrivateKey.getAlgorithm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。