当前位置: 首页>>代码示例>>Java>>正文


Java ECPrivateKeyParameters类代码示例

本文整理汇总了Java中org.spongycastle.crypto.params.ECPrivateKeyParameters的典型用法代码示例。如果您正苦于以下问题:Java ECPrivateKeyParameters类的具体用法?Java ECPrivateKeyParameters怎么用?Java ECPrivateKeyParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ECPrivateKeyParameters类属于org.spongycastle.crypto.params包,在下文中一共展示了ECPrivateKeyParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: performRawKeyAgreement

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
byte[] performRawKeyAgreement(PrivateKey priv, PublicKey pub)
		throws GeneralSecurityException {
	if (!(priv instanceof Sec1PrivateKey))
		throw new IllegalArgumentException();
	if (!(pub instanceof Sec1PublicKey))
		throw new IllegalArgumentException();
	ECPrivateKeyParameters ecPriv = ((Sec1PrivateKey) priv).getKey();
	ECPublicKeyParameters ecPub = ((Sec1PublicKey) pub).getKey();
	long now = System.currentTimeMillis();
	ECDHCBasicAgreement agreement = new ECDHCBasicAgreement();
	agreement.init(ecPriv);
	byte[] secret = agreement.calculateAgreement(ecPub).toByteArray();
	long duration = System.currentTimeMillis() - now;
	if (LOG.isLoggable(INFO))
		LOG.info("Deriving shared secret took " + duration + " ms");
	return secret;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:18,代码来源:CryptoComponentImpl.java

示例2: parsePrivateKey

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
@Override
public PrivateKey parsePrivateKey(byte[] encodedKey)
		throws GeneralSecurityException {
	long now = System.currentTimeMillis();
	if (encodedKey.length != privateKeyBytes)
		throw new GeneralSecurityException();
	BigInteger d = new BigInteger(1, encodedKey); // Positive signum
	// Verify that the private value is < n
	if (d.compareTo(params.getN()) >= 0)
		throw new GeneralSecurityException();
	// Construct a private key from the private value and the params
	ECPrivateKeyParameters k = new ECPrivateKeyParameters(d, params);
	PrivateKey p = new Sec1PrivateKey(k, keyBits);
	long duration = System.currentTimeMillis() - now;
	if (LOG.isLoggable(INFO))
		LOG.info("Parsing private key took " + duration + " ms");
	return p;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:19,代码来源:Sec1KeyParser.java

示例3: doSign

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
protected ECDSASignature doSign(Sha256Hash input, BigInteger privateKeyForSigning) {
    if (Secp256k1Context.isEnabled()) {
        try {
            byte[] signature = NativeSecp256k1.sign(input.getBytes(),
                    CryptoUtils.bigIntegerToBytes(privateKeyForSigning, 32));
            return ECDSASignature.decodeFromDER(signature);
        } catch (NativeSecp256k1Util.AssertFailException e) {
            log.error("Caught AssertFailException inside secp256k1", e);
            throw new RuntimeException(e);
        }
    }
    if (FAKE_SIGNATURES)
        // return TransactionSignature.dummy();
        checkNotNull(privateKeyForSigning);
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input.getBytes());
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:marvin-we,项目名称:crypto-core,代码行数:21,代码来源:ECKey.java

示例4: doSign

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers
 * and put them in ECDSASignature
 *
 * @param input to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
    if (input.length != 32) {
        throw new IllegalArgumentException("Expected 32 byte input to ECDSA signature, not " + input.length);
    }
    // No decryption of private key required.
    if (privKey == null)
        throw new MissingPrivateKeyException();
    if (privKey instanceof BCECPrivateKey) {
        ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
        ECPrivateKeyParameters privKeyParams = new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE);
        signer.init(true, privKeyParams);
        BigInteger[] components = signer.generateSignature(input);
        return new ECDSASignature(components[0], components[1]).toCanonicalised();
    } else {
        try {
            final Signature ecSig = ECSignatureFactory.getRawInstance(provider);
            ecSig.initSign(privKey);
            ecSig.update(input);
            final byte[] derSignature = ecSig.sign();
            return ECDSASignature.decodeFromDER(derSignature).toCanonicalised();
        } catch (SignatureException | InvalidKeyException ex) {
            throw new RuntimeException("ECKey signing error", ex);
        }
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:33,代码来源:ECKey.java

示例5: ECKey

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
/**
 * Generates an entirely new keypair. Point compression is used so the resulting public key will be 33 bytes
 * (32 for the co-ordinate and 1 byte to represent the y bit).
 */
public ECKey() {
    ECKeyPairGenerator generator = new ECKeyPairGenerator();
    ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(ecParams, secureRandom);
    generator.init(keygenParams);
    AsymmetricCipherKeyPair keypair = generator.generateKeyPair();
    ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate();
    ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic();
    priv = privParams.getD();
    // Unfortunately Bouncy Castle does not let us explicitly change a point to be compressed, even though it
    // could easily do so. We must re-build it here so the ECPoints withCompression flag can be set to true.
    ECPoint uncompressed = pubParams.getQ();
    ECPoint compressed = compressPoint(uncompressed);
    pub = compressed.getEncoded();

    creationTimeSeconds = Utils.now().getTime() / 1000;
}
 
开发者ID:appteam-nith,项目名称:NithPointsj,代码行数:21,代码来源:ECKey.java

示例6: deriveSharedSecret

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
byte[] deriveSharedSecret(PrivateKey priv, PublicKey pub)
		throws GeneralSecurityException {
	if(!(priv instanceof Sec1PrivateKey))
		throw new IllegalArgumentException();
	if(!(pub instanceof Sec1PublicKey))
		throw new IllegalArgumentException();
	ECPrivateKeyParameters ecPriv = ((Sec1PrivateKey) priv).getKey();
	ECPublicKeyParameters ecPub = ((Sec1PublicKey) pub).getKey();
	long now = System.currentTimeMillis();
	ECDHCBasicAgreement agreement = new ECDHCBasicAgreement();
	agreement.init(ecPriv);
	byte[] secret = agreement.calculateAgreement(ecPub).toByteArray();
	long duration = System.currentTimeMillis() - now;
	if(LOG.isLoggable(INFO))
		LOG.info("Deriving shared secret took " + duration + " ms");
	return secret;
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:18,代码来源:CryptoComponentImpl.java

示例7: parsePrivateKey

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
public PrivateKey parsePrivateKey(byte[] encodedKey)
		throws GeneralSecurityException {
	long now = System.currentTimeMillis();
	if(encodedKey.length != privateKeyBytes)
		throw new GeneralSecurityException();
	BigInteger d = new BigInteger(1, encodedKey); // Positive signum
	// Verify that the private value is < n
	if(d.compareTo(params.getN()) >= 0)
		throw new GeneralSecurityException();
	// Construct a private key from the private value and the params
	ECPrivateKeyParameters k = new ECPrivateKeyParameters(d, params);
	PrivateKey p = new Sec1PrivateKey(k, keyBits);
	long duration = System.currentTimeMillis() - now;
	if(LOG.isLoggable(INFO))
		LOG.info("Parsing private key took " + duration + " ms");
	return p;
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:18,代码来源:Sec1KeyParser.java

示例8: initSign

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
@Override
public void initSign(PrivateKey k) throws GeneralSecurityException {
	if (!(k instanceof Sec1PrivateKey))
		throw new IllegalArgumentException();
	ECPrivateKeyParameters priv = ((Sec1PrivateKey) k).getKey();
	signer.init(true, new ParametersWithRandom(priv, secureRandom));
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:8,代码来源:SignatureImpl.java

示例9: generateAgreementKeyPair

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
@Override
public KeyPair generateAgreementKeyPair() {
	AsymmetricCipherKeyPair keyPair =
			agreementKeyPairGenerator.generateKeyPair();
	// Return a wrapper that uses the SEC 1 encoding
	ECPublicKeyParameters ecPublicKey =
			(ECPublicKeyParameters) keyPair.getPublic();
	PublicKey publicKey = new Sec1PublicKey(ecPublicKey
	);
	ECPrivateKeyParameters ecPrivateKey =
			(ECPrivateKeyParameters) keyPair.getPrivate();
	PrivateKey privateKey = new Sec1PrivateKey(ecPrivateKey,
			AGREEMENT_KEY_PAIR_BITS);
	return new KeyPair(publicKey, privateKey);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:16,代码来源:CryptoComponentImpl.java

示例10: generateSignatureKeyPair

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
@Override
public KeyPair generateSignatureKeyPair() {
	AsymmetricCipherKeyPair keyPair =
			signatureKeyPairGenerator.generateKeyPair();
	// Return a wrapper that uses the SEC 1 encoding
	ECPublicKeyParameters ecPublicKey =
			(ECPublicKeyParameters) keyPair.getPublic();
	PublicKey publicKey = new Sec1PublicKey(ecPublicKey
	);
	ECPrivateKeyParameters ecPrivateKey =
			(ECPrivateKeyParameters) keyPair.getPrivate();
	PrivateKey privateKey = new Sec1PrivateKey(ecPrivateKey,
			SIGNATURE_KEY_PAIR_BITS);
	return new KeyPair(publicKey, privateKey);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:16,代码来源:CryptoComponentImpl.java

示例11: generateKeyPair

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
KeyPair generateKeyPair() {
	AsymmetricCipherKeyPair keyPair = generator.generateKeyPair();
	// Return a wrapper that uses the SEC 1 encoding
	ECPublicKeyParameters ecPublicKey =
			(ECPublicKeyParameters) keyPair.getPublic();
	PublicKey publicKey = new Sec1PublicKey(ecPublicKey);
	ECPrivateKeyParameters ecPrivateKey =
			(ECPrivateKeyParameters) keyPair.getPrivate();
	PrivateKey privateKey =
			new Sec1PrivateKey(ecPrivateKey, MESSAGE_KEY_BITS);
	return new KeyPair(publicKey, privateKey);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:13,代码来源:MessageEncrypter.java

示例12: ECKey

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
/**
 * Generates an entirely new keypair with the given {@link SecureRandom}
 * object. Point compression is used so the resulting public key will be 33
 * bytes (32 for the co-ordinate and 1 byte to represent the y bit).
 */
public ECKey(SecureRandom secureRandom) {
    ECKeyPairGenerator generator = new ECKeyPairGenerator();
    ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(CURVE, secureRandom);
    generator.init(keygenParams);
    AsymmetricCipherKeyPair keypair = generator.generateKeyPair();
    ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate();
    ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic();
    priv = privParams.getD();
    pub = new LazyECPoint(CURVE.getCurve(), pubParams.getQ().getEncoded(true));
    creationTimeSeconds = CryptoUtils.currentTimeSeconds();
}
 
开发者ID:marvin-we,项目名称:crypto-core,代码行数:17,代码来源:ECKey.java

示例13: doSign

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers
 * and put them in ECDSASignature
 *
 * @param input to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
  if (input.length != 32) {
    throw new IllegalArgumentException(
        "Expected 32 byte input to ECDSA signature, not " + input.length);
  }
  // No decryption of private key required.
  if (privKey == null) throw new MissingPrivateKeyException();
  if (privKey instanceof BCECPrivateKey) {
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKeyParams =
        new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE);
    signer.init(true, privKeyParams);
    BigInteger[] components = signer.generateSignature(input);
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
  } else {
    try {
      Signature ecSig = ECSignatureFactory.getRawInstance(provider);
      ecSig.initSign(privKey);
      ecSig.update(input);
      byte[] derSignature = ecSig.sign();
      return ECDSASignature.decodeFromDER(derSignature)
          .toCanonicalised();
    } catch (SignatureException | InvalidKeyException ex) {
      throw new RuntimeException("ECKey signing error", ex);
    }
  }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:35,代码来源:ECKey.java

示例14: signAndFromatToRS

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
/**
 * UAF_ALG_SIGN_SECP256R1_ECDSA_SHA256_RAW 0x01
 * An ECDSA signature on the NIST secp256r1 curve which MUST have raw R and S buffers, encoded in big-endian order.
 * I.e. [R (32 bytes), S (32 bytes)]
 * 
 * @param priv - Private key
 * @param input - Data to sign 
 * @return BigInteger[] - [R,S]
 */
public static BigInteger[] signAndFromatToRS(PrivateKey priv, byte[] input) {
	X9ECParameters params = SECNamedCurves.getByName("secp256r1");
	ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(),
			params.getG(), params.getN(), params.getH());
	if (priv == null)
		throw new IllegalStateException(
				"This ECKey does not have the private key necessary for signing.");
	ECDSASigner signer = new ECDSASigner();
	ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(
			((ECPrivateKey) priv).getS(), ecParams);
	signer.init(true, privKey);
	BigInteger[] sigs = signer.generateSignature(input);
	return sigs;
}
 
开发者ID:zsavvas,项目名称:ReCRED_FIDO_UAF_OIDC,代码行数:24,代码来源:NamedCurve.java

示例15: sign

import org.spongycastle.crypto.params.ECPrivateKeyParameters; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers. In the NithPoints protocol, they are
 * usually encoded using DER format, so you want {@link com.google.NithPoints.core.ECKey.ECDSASignature#encodeToDER()}
 * instead. However sometimes the independent components can be useful, for instance, if you're doing to do further
 * EC maths on them.
 *
 * @param aesKey The AES key to use for decryption of the private key. If null then no decryption is required.
 * @throws KeyCrypterException if this ECKey doesn't have a private part.
 */
public ECDSASignature sign(Sha256Hash input, KeyParameter aesKey) throws KeyCrypterException {
    // The private key bytes to use for signing.
    BigInteger privateKeyForSigning;

    if (isEncrypted()) {
        // The private key needs decrypting before use.
        if (aesKey == null) {
            throw new KeyCrypterException("This ECKey is encrypted but no decryption key has been supplied.");
        }

        if (keyCrypter == null) {
            throw new KeyCrypterException("There is no KeyCrypter to decrypt the private key for signing.");
        }

        privateKeyForSigning = new BigInteger(1, keyCrypter.decrypt(encryptedPrivateKey, aesKey));
        // Check encryption was correct.
        if (!Arrays.equals(pub, publicKeyFromPrivate(privateKeyForSigning, isCompressed())))
            throw new KeyCrypterException("Could not decrypt bytes");
    } else {
        // No decryption of private key required.
        if (priv == null) {
            throw new KeyCrypterException("This ECKey does not have the private key necessary for signing.");
        } else {
            privateKeyForSigning = priv;
        }
    }

    ECDSASigner signer = new ECDSASigner();
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, ecParams);
    signer.init(true, privKey);
    BigInteger[] sigs = signer.generateSignature(input.getBytes());
    return new ECDSASignature(sigs[0], sigs[1]);
}
 
开发者ID:appteam-nith,项目名称:NithPointsj,代码行数:43,代码来源:ECKey.java


注:本文中的org.spongycastle.crypto.params.ECPrivateKeyParameters类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。