本文整理汇总了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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}