当前位置: 首页>>代码示例>>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;未经允许,请勿转载。