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


Java AsymmetricCipherKeyPair.getPublic方法代碼示例

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


在下文中一共展示了AsymmetricCipherKeyPair.getPublic方法的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.getPublic方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。