本文整理汇总了Java中org.whispersystems.curve25519.Curve25519类的典型用法代码示例。如果您正苦于以下问题:Java Curve25519类的具体用法?Java Curve25519怎么用?Java Curve25519使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Curve25519类属于org.whispersystems.curve25519包,在下文中一共展示了Curve25519类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sharedSecret
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
private static ByteString sharedSecret(@Nonnull byte[] publicKey, @Nonnull byte[] privateKey) {
final byte[] s =
Curve25519.getInstance(Curve25519.BEST).calculateAgreement(publicKey, privateKey);
final byte[] k = new byte[32];
HSalsa20.hsalsa20(k, new byte[16], s);
return ByteString.of(k);
}
示例2: encrypt
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static ByteString encrypt(
ByteString privateKey, Collection<ByteString> publicKeys, ByteString plaintext, int padding) {
final ByteString sk = SimpleBox.generateSecretKey();
final SimpleBox session = new SimpleBox(sk);
// encode and encrypt header
final int dataOffset = publicKeys.size() * (KEY_LEN + OVERHEAD);
final int dataLength = plaintext.size() + SIG_LEN;
final ByteString header =
session.seal(new Buffer().writeInt(dataOffset).writeInt(dataLength).readByteString());
// encrypt a copy of the session key with each public key
final Buffer keysBuf = new Buffer();
for (ByteString pk : publicKeys) {
final SimpleBox shared = new SimpleBox(pk, privateKey);
keysBuf.write(shared.seal(sk));
}
final ByteString keys = keysBuf.readByteString();
// sign the encrypted header, the encrypted keys, and the unencrypted plaintext
final ByteString signed =
new Buffer().write(header).write(keys).write(plaintext).readByteString();
final byte[] sig =
Curve25519.getInstance(Curve25519.BEST)
.calculateSignature(privateKey.toByteArray(), signed.toByteArray());
// encrypt the plaintext and the signature
final ByteString data = new Buffer().write(sig).write(plaintext).readByteString();
final ByteString encData = session.seal(data);
// generate random padding
final byte[] pad = new byte[padding];
if (padding > 0) {
final SecureRandom r = new SecureRandom();
r.nextBytes(pad);
}
// return the encrypted header, the encrypted keys, and the encrypted plaintext and signature
return new Buffer().write(header).write(keys).write(encData).write(pad).readByteString();
}
示例3: computeSharedSecret
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
/**
* Client-side shared-secret agreement
* @param beaconPrivateKey Advertiser private key
* @return Shared secret between server and client
*/
public static byte[] computeSharedSecret(byte[] serverPublicKey, byte[] beaconPrivateKey) {
// this should yield the exact same result as in EIDResolver.registerBeacon
// Util.log("Server public key: " + Util.binToHex(serverPublicKey));
// Util.log("Advertiser private key: " + Util.binToHex(beaconPrivateKey));
return Curve25519.getInstance(Curve25519.BEST).calculateAgreement(serverPublicKey, beaconPrivateKey);
}
示例4: registerUrl
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
/**
* Registers a new long URL resource.
* @param url The long URL.
* @param urlPublicKey The public key of the new URL. Each URL should have its own key-pair.
* If null, a public key will be generated using Curve25519.generateKeyPair()
* @param callback Result callback.
*/
void registerUrl(String url, byte[] urlPublicKey, Callback<UrlResource> callback) {
if (null == urlPublicKey) {
Curve25519KeyPair keyPair = Curve25519.getInstance(Curve25519.BEST).generateKeyPair();
urlPublicKey = keyPair.getPublicKey();
}
mApiService.registerUrl(new UrlResource(mApiKey, url, urlPublicKey))
.enqueue(new SimpleResultHandler<>(callback));
}
示例5: calculateAgreement
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static byte[] calculateAgreement(ECPublicKey publicKey, ECPrivateKey privateKey)
throws InvalidKeyException
{
if (publicKey.getType() != privateKey.getType()) {
throw new InvalidKeyException("Public and private keys must be of the same type!");
}
if (publicKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.calculateAgreement(((DjbECPublicKey) publicKey).getPublicKey(),
((DjbECPrivateKey) privateKey).getPrivateKey());
} else {
throw new InvalidKeyException("Unknown type: " + publicKey.getType());
}
}
示例6: verifySignature
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static boolean verifySignature(ECPublicKey signingKey, byte[] message, byte[] signature)
throws InvalidKeyException
{
if (signingKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.verifySignature(((DjbECPublicKey) signingKey).getPublicKey(), message, signature);
} else {
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
}
}
示例7: calculateSignature
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static byte[] calculateSignature(ECPrivateKey signingKey, byte[] message)
throws InvalidKeyException
{
if (signingKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.calculateSignature(((DjbECPrivateKey) signingKey).getPrivateKey(), message);
} else {
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
}
}
示例8: calculateVrfSignature
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static byte[] calculateVrfSignature(ECPrivateKey signingKey, byte[] message)
throws InvalidKeyException
{
if (signingKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.calculateVrfSignature(((DjbECPrivateKey)signingKey).getPrivateKey(), message);
} else {
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
}
}
示例9: verifyVrfSignature
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static byte[] verifyVrfSignature(ECPublicKey signingKey, byte[] message, byte[] signature)
throws InvalidKeyException, VrfSignatureVerificationFailedException
{
if (signingKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.verifyVrfSignature(((DjbECPublicKey) signingKey).getPublicKey(), message, signature);
} else {
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
}
}
示例10: decrypt
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static ByteString decrypt(
ByteString publicKey, ByteString privateKey, ByteString ciphertext) {
try {
final SimpleBox shared = new SimpleBox(publicKey, privateKey);
final Buffer in = new Buffer().write(ciphertext);
// copy the fixed-length header
final ByteString encHeader = in.readByteString(HEADER_LEN + OVERHEAD);
// iterate through key-sized chunks, trying to decrypt them
Optional<ByteString> sk = Optional.empty();
while (in.size() > KEY_LEN + OVERHEAD) {
final Optional<ByteString> result = shared.open(in.readByteString(KEY_LEN + OVERHEAD));
if (result.isPresent()) {
sk = result;
break;
}
}
final SimpleBox session = new SimpleBox(sk.orElseThrow(IllegalArgumentException::new));
// decrypt the header
final Buffer header =
new Buffer().write(session.open(encHeader).orElseThrow(IllegalArgumentException::new));
final int dataOffset = header.readInt();
final int dataLength = header.readInt();
// skip the other keys
in.skip((dataOffset + HEADER_LEN + OVERHEAD) - (ciphertext.size() - in.size()));
// decrypt the data and signature
final ByteString encData = in.readByteString(dataLength + OVERHEAD);
final Buffer data =
new Buffer().write(session.open(encData).orElseThrow(IllegalArgumentException::new));
final ByteString sig = data.readByteString(SIG_LEN);
final ByteString plaintext = data.readByteString();
// rebuild the signed data and verify the signature
final ByteString signed =
new Buffer()
.write(ciphertext.substring(0, HEADER_LEN + OVERHEAD + dataOffset))
.write(plaintext)
.readByteString();
if (!Curve25519.getInstance(Curve25519.BEST)
.verifySignature(publicKey.toByteArray(), signed.toByteArray(), sig.toByteArray())) {
throw new IllegalArgumentException();
}
// return the plaintext
return plaintext;
} catch (IOException e) {
throw new IllegalArgumentException();
}
}
示例11: LocalEIDResolver
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public LocalEIDResolver() {
mEC = Curve25519.getInstance(Curve25519.BEST);
// fixme - read keypair from storage
mKeyPair = mEC.generateKeyPair();
}
示例12: isNative
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static boolean isNative() {
return Curve25519.getInstance(BEST).isNative();
}
示例13: generateKeyPair
import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static ECKeyPair generateKeyPair() {
Curve25519KeyPair keyPair = Curve25519.getInstance(BEST).generateKeyPair();
return new ECKeyPair(new DjbECPublicKey(keyPair.getPublicKey()),
new DjbECPrivateKey(keyPair.getPrivateKey()));
}