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


Java AsymmetricCipherKeyPair.getPrivate方法代码示例

本文整理汇总了Java中org.spongycastle.crypto.AsymmetricCipherKeyPair.getPrivate方法的典型用法代码示例。如果您正苦于以下问题:Java AsymmetricCipherKeyPair.getPrivate方法的具体用法?Java AsymmetricCipherKeyPair.getPrivate怎么用?Java AsymmetricCipherKeyPair.getPrivate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongycastle.crypto.AsymmetricCipherKeyPair的用法示例。


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

示例1: ECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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

示例2: validateDHKeyPair

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
/**
 * A helper routine that verifies that a given Diffie-Hellman keypair is valid.
 *
 * @return Returns the private key as a BigInteger for further verification.
 */
public BigInteger validateDHKeyPair(AsymmetricCipherKeyPair pair) {
  DHPrivateKeyParameters priv = (DHPrivateKeyParameters) pair.getPrivate();
  DHPublicKeyParameters pub = (DHPublicKeyParameters) pair.getPublic();

  assertNotNull(priv);
  assertNotNull(pub);

  // Check that the public key == g^(private key) mod p.
  // This test is overkill, but validates that the we've hooked into the right library.
  BigInteger g = Crypto.DH_GROUP_PARAMETERS.getG();
  BigInteger p = Crypto.DH_GROUP_PARAMETERS.getP();

  assertEquals("Tests that the public key y == g^(private key x) mod p",
               pub.getY(), g.modPow(priv.getX(), p));

  BigInteger foo = new BigInteger(Crypto.DH_SUBGROUP_SIZE, Crypto.random);
  BigInteger gToTheFoo = g.modPow(foo, Crypto.DH_GROUP_PARAMETERS.getP());
  BigInteger fooInverse = foo.modInverse(Crypto.DH_GROUP_PARAMETERS.getQ());
  BigInteger newG = gToTheFoo.modPow(fooInverse, Crypto.DH_GROUP_PARAMETERS.getP());

  assertEquals("Tests that we can inverse group exponentiation", g, newG);

  return priv.getX();
}
 
开发者ID:casific,项目名称:murmur,代码行数:30,代码来源:CryptoTest.java

示例3: encodeDecodeKeysTest

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
/**
 * Check that the individual encode/decode private/public key methods reverse each other.
 * Check that the generatePublicID/generatePrivateID methods are reversed by the 
 * corresponding decode method.
 */
@Test
public void encodeDecodeKeysTest() throws IOException {
  AsymmetricCipherKeyPair keypair = Crypto.generateDHKeyPair();
  DHPrivateKeyParameters privKey = (DHPrivateKeyParameters) keypair.getPrivate();
  DHPublicKeyParameters pubKey = (DHPublicKeyParameters) keypair.getPublic();

  assertEquals(pubKey, Crypto.decodeDHPublicKey(Crypto.encodeDHPublicKey(pubKey)));
  assertEquals(privKey, Crypto.decodeDHPrivateKey(Crypto.encodeDHPrivateKey(privKey)));

  assertEquals(pubKey, Crypto.decodeDHPublicKey(Crypto.generatePublicID(keypair)));
  assertEquals(privKey, Crypto.decodeDHPrivateKey(Crypto.generatePrivateID(keypair)));

  // Took this out because sometimes pubkey is 129 and sometimes it's 128.
  // Not sure why that is (or what else to test here).
  // int BYTES_IN_PUBKEY = 128;
  // int BYTES_IN_PRIVKEY = 21;
  // assertEquals(BYTES_IN_PUBKEY, Crypto.encodeDHPublicKey(pubKey).length);
  // assertEquals(BYTES_IN_PRIVKEY, Crypto.encodeDHPrivateKey(privKey).length);
}
 
开发者ID:casific,项目名称:murmur,代码行数:25,代码来源:CryptoTest.java

示例4: ECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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(CURVE, 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.currentTimeMillis() / 1000;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:21,代码来源:ECKey.java

示例5: ECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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(CURVE, 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.currentTimeMillis() / 1000;
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:21,代码来源:ECKey.java

示例6: ECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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(CURVE, 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:9cat,项目名称:templecoin-java,代码行数:21,代码来源:ECKey.java

示例7: ECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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(CURVE, 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.currentTimeSeconds();
}
 
开发者ID:keremhd,项目名称:mintcoinj,代码行数:21,代码来源:ECKey.java

示例8: generateAgreementKeyPair

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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

示例9: generateSignatureKeyPair

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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

示例10: generateKeyPair

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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

示例11: ECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
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 = pubParams.getQ();
    creationTimeSeconds = System.currentTimeMillis();
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:12,代码来源:ECKey.java

示例12: ECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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).
 *
 * @param secureRandom -
 */
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 = CURVE.getCurve().decodePoint(pubParams.getQ().getEncoded(true));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:ECKey.java

示例13: ECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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 = Utils.currentTimeSeconds();
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:16,代码来源:ECKey.java

示例14: ECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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

示例15: BtcECKey

import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的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 BtcECKey(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 = Utils.currentTimeSeconds();
}
 
开发者ID:rsksmart,项目名称:bitcoinj-thin,代码行数:16,代码来源:BtcECKey.java


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