• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Curve25519类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
}
 
开发者ID:codahale,项目名称:xsalsa20poly1305,代码行数:8,代码来源:SecretBox.java


示例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();
}
 
开发者ID:codahale,项目名称:veil,代码行数:41,代码来源:Veil.java


示例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);
    }
 
开发者ID:adriancretu,项目名称:beacons-android,代码行数:12,代码来源:EIDUtils.java


示例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));
}
 
开发者ID:uriio,项目名称:uriio-android,代码行数:17,代码来源:ApiClient.java


示例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());
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:16,代码来源:Curve.java


示例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());
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:11,代码来源:Curve.java


示例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());
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:11,代码来源:Curve.java


示例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());
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:11,代码来源:Curve.java


示例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());
  }
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:11,代码来源:Curve.java


示例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();
  }
}
 
开发者ID:codahale,项目名称:veil,代码行数:54,代码来源:Veil.java


示例11: LocalEIDResolver

import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public LocalEIDResolver() {
    mEC = Curve25519.getInstance(Curve25519.BEST);

    // fixme - read keypair from storage
    mKeyPair = mEC.generateKeyPair();
}
 
开发者ID:adriancretu,项目名称:beacons-android,代码行数:7,代码来源:LocalEIDResolver.java


示例12: isNative

import org.whispersystems.curve25519.Curve25519; //导入依赖的package包/类
public static boolean isNative() {
  return Curve25519.getInstance(BEST).isNative();
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:4,代码来源:Curve.java


示例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()));
}
 
开发者ID:signalapp,项目名称:libsignal-protocol-java,代码行数:7,代码来源:Curve.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Callback类代码示例发布时间:2022-05-22
下一篇:
Java AnimatedCircleLoadingView类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap