本文整理汇总了Java中org.spongycastle.crypto.AsymmetricCipherKeyPair类的典型用法代码示例。如果您正苦于以下问题:Java AsymmetricCipherKeyPair类的具体用法?Java AsymmetricCipherKeyPair怎么用?Java AsymmetricCipherKeyPair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AsymmetricCipherKeyPair类属于org.spongycastle.crypto包,在下文中一共展示了AsymmetricCipherKeyPair类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: generateAndStoreDeviceID
import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
/**
* If the device has not previously generated and persisted its device ID (aka
* public/private keypair for PSI), generates and stores said ID.
*
* If the ID is already stored, this harmlessly does nothing.
*/
private void generateAndStoreDeviceID() {
String privateDeviceID = store.get(DEVICE_PRIVATE_ID_KEY);
String publicDeviceID = store.get(DEVICE_PUBLIC_ID_KEY);
if (privateDeviceID == null || publicDeviceID == null) {
// This would be very strange, if only half the ID was stored.
if (privateDeviceID != publicDeviceID) {
if (privateDeviceID == null) {
Log.wtf(TAG, "Only one of private and public ID are stored! Public is stored, private is null.");
} else {
Log.wtf(TAG, "Only one of private and public ID are stored! Private is stored, public is null.");
}
}
AsymmetricCipherKeyPair keypair = Crypto.generateUserID();
privateDeviceID = bytesToBase64(Crypto.generatePrivateID(keypair));
publicDeviceID = bytesToBase64(Crypto.generatePublicID(keypair));
store.put(DEVICE_PRIVATE_ID_KEY, privateDeviceID);
store.put(DEVICE_PUBLIC_ID_KEY, publicDeviceID);
}
}
开发者ID:casific,项目名称:murmur,代码行数:27,代码来源:FriendStore.java
示例3: generateAndStoreDeviceID
import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
/**
* If the device has not previously generated and persisted its device ID (aka
* public/private keypair for PSI), generates and stores said ID.
*
* If the ID is already stored, this harmlessly does nothing.
*/
private void generateAndStoreDeviceID(Context context, int encryption) {
if(store == null) store = new StorageBase(context, encryption);
String privateDeviceID = store.get(DEVICE_PRIVATE_ID_KEY);
String publicDeviceID = store.get(DEVICE_PUBLIC_ID_KEY);
if (privateDeviceID == null || publicDeviceID == null) {
// This would be very strange, if only half the ID was stored.
if (privateDeviceID != publicDeviceID) {
if (privateDeviceID == null) {
log.error( "Only one of private and public ID are stored! Public is stored, private is null.");
} else {
log.error( "Only one of private and public ID are stored! Private is stored, public is null.");
}
}
AsymmetricCipherKeyPair keypair = Crypto.generateUserID();
privateDeviceID = bytesToBase64(Crypto.generatePrivateID(keypair));
publicDeviceID = bytesToBase64(Crypto.generatePublicID(keypair));
store.put(DEVICE_PRIVATE_ID_KEY, privateDeviceID);
store.put(DEVICE_PUBLIC_ID_KEY, publicDeviceID);
}
}
开发者ID:casific,项目名称:murmur,代码行数:29,代码来源:FriendStore.java
示例4: 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
示例5: 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
示例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.currentTimeMillis() / 1000;
}
开发者ID:HashEngineering,项目名称:megacoinj,代码行数: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.currentTimeMillis() / 1000;
}
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:21,代码来源:ECKey.java
示例8: 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
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: 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
示例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).
*
* @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
示例15: 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
示例16: 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
示例17: 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
示例18: generateDHKeyPair
import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
/**
* Generates a Diffie-Hellman keypair of the default size.
*
* @return The generated Diffie-Hellman keypair or null upon failure.
*/
protected static AsymmetricCipherKeyPair generateDHKeyPair() {
try {
KeyGenerationParameters kgp = new DHKeyGenerationParameters(random, DH_GROUP_PARAMETERS);
DHKeyPairGenerator gen = new DHKeyPairGenerator();
gen.init(kgp);
return gen.generateKeyPair();
} catch (InvalidParameterException e) {
Log.e(TAG, "InvalidParameterException while generating a Diffie-Hellman keypair " + e);
}
return null;
}
开发者ID:casific,项目名称:murmur,代码行数:19,代码来源:Crypto.java
示例19: generateDHKeyPair
import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
/**
* Generates a Diffie-Hellman keypair of the default size.
*
* @return The generated Diffie-Hellman keypair or null upon failure.
*/
protected static AsymmetricCipherKeyPair generateDHKeyPair() {
try {
KeyGenerationParameters kgp = new DHKeyGenerationParameters(random, DH_GROUP_PARAMETERS);
DHKeyPairGenerator gen = new DHKeyPairGenerator();
gen.init(kgp);
return gen.generateKeyPair();
} catch (InvalidParameterException e) {
log.error( "InvalidParameterException while generating a Diffie-Hellman keypair " + e);
}
return null;
}
开发者ID:casific,项目名称:murmur,代码行数:19,代码来源:Crypto.java
示例20: generateDHPairTest
import org.spongycastle.crypto.AsymmetricCipherKeyPair; //导入依赖的package包/类
/**
* Tests that we can generate a valid Diffie-Hellman keypair, and that each
* call creates a different keypair.
*/
@Test
public void generateDHPairTest() {
AsymmetricCipherKeyPair pair1 = Crypto.generateDHKeyPair();
assertNotNull(pair1);
BigInteger priv1 = validateDHKeyPair(pair1);
AsymmetricCipherKeyPair pair2 = Crypto.generateDHKeyPair();
assertNotNull(pair2);
BigInteger priv2 = validateDHKeyPair(pair2);
assertNotEquals("Testing that two Diffie-Hellman keypairs have different private keys",
priv1, priv2);
}
开发者ID:casific,项目名称:murmur,代码行数:18,代码来源:CryptoTest.java
注:本文中的org.spongycastle.crypto.AsymmetricCipherKeyPair类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论