当前位置: 首页>>代码示例>>Java>>正文


Java EdDSAPublicKey类代码示例

本文整理汇总了Java中net.i2p.crypto.eddsa.EdDSAPublicKey的典型用法代码示例。如果您正苦于以下问题:Java EdDSAPublicKey类的具体用法?Java EdDSAPublicKey怎么用?Java EdDSAPublicKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EdDSAPublicKey类属于net.i2p.crypto.eddsa包,在下文中一共展示了EdDSAPublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractOpenSSHPublic

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * @param pair KeyPair to convert to an OpenSSH public key
 * @return OpenSSH-encoded pubkey
 */
public static byte[] extractOpenSSHPublic(KeyPair pair) {
	try {
		PublicKey pubKey = pair.getPublic();
		if (pubKey instanceof RSAPublicKey) {
			return RSASHA1Verify.encodeSSHRSAPublicKey((RSAPublicKey) pubKey);
		} else if (pubKey instanceof DSAPublicKey) {
			return DSASHA1Verify.encodeSSHDSAPublicKey((DSAPublicKey) pubKey);
		} else if (pubKey instanceof ECPublicKey) {
			return ECDSASHA2Verify.encodeSSHECDSAPublicKey((ECPublicKey) pubKey);
		} else if (pubKey instanceof EdDSAPublicKey) {
			return Ed25519Verify.encodeSSHEd25519PublicKey((EdDSAPublicKey) pubKey);
		} else {
			return null;
		}
	} catch (IOException e) {
		return null;
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:PubkeyUtils.java

示例2: testConstructionUsingMultipleThreads

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * Tests concurrently creating an instance of {@link Ed25519Sha256Condition}. This test validates
 * the fix for Github issue #40 where construction of this class was not thread-safe.
 *
 * @see "https://github.com/interledger/java-crypto-conditions/issues/40"
 * @see "https://github.com/junit-team/junit4/wiki/multithreaded-code-and-concurrency"
 */
@Test
public void testConstructionUsingMultipleThreads() throws Exception {
  final KeyPair keypair = this.constructEd25519KeyPair();

  final Runnable runnableTest = () -> {
    final Ed25519Sha256Condition ed25519Sha256Condition = new Ed25519Sha256Condition(
        (EdDSAPublicKey) keypair.getPublic());

    assertThat(ed25519Sha256Condition.getType(), is(CryptoConditionType.ED25519_SHA256));
    assertThat(ed25519Sha256Condition.getCost(), is(131072L));
    assertThat(CryptoConditionUri.toUri(ed25519Sha256Condition), is(URI.create(
        "ni:///sha-256;aJ5kk1zn2qrQQO5QhYZXoGigv0Y5rSafiV3BUM1F9hM?cost=131072&"
            + "fpt=ed25519-sha-256")));
    assertThat(BaseEncoding.base64().encode(ed25519Sha256Condition.getFingerprint()),
        is("aJ5kk1zn2qrQQO5QhYZXoGigv0Y5rSafiV3BUM1F9hM="));
    assertThat(BaseEncoding.base64().encode(ed25519Sha256Condition
            .constructFingerprintContents((EdDSAPublicKey) keypair.getPublic())),
        is("MCKAIDauG5fFd65q+wKU6Rg5+nsfkzJ5G58sXVhoGQJfSi8d"));
  };

  this.runConcurrent(1, runnableTest);
  this.runConcurrent(runnableTest);
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:31,代码来源:Ed25519Sha256ConditionTest.java

示例3: generateBubiAddress

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * 根据公钥生成布比地址 1.对Q进行RIPEMD160算法得到20字节的N,即N = RIPEMD160(Q)
 * 2.在N前面加4字节前缀和1字节版本号。即M=0XE69A73FF01+N
 * 3.对M进行两次SHA256算法取前四字节,即Checksum=SHA256(SHA256(M))的前4字节
 * 4.将Checksum加到M后面,即S=M+Checksum 5.对S进行Base58编码即得到布比地址bubixxxxxxxxxxxx
 *
 * @param pubKey
 * @return 布比地址字符串
 */
private static String generateBubiAddress(EdDSAPublicKey pubKey){
    try {
        MessageDigest md = MessageDigest.getInstance("RIPEMD160");
        md.update(pubKey.getAbyte());
        byte[] N = md.digest();

        byte[] pubKeyheadArr = Utils.hexToBytes("E69A73FF01");
        byte[] M = ArrayUtils.addAll(pubKeyheadArr, N);
        md = MessageDigest.getInstance("SHA-256");
        md.update(M);
        byte[] M_256_1 = md.digest();
        md.update(M_256_1);
        byte[] M_256_2 = md.digest();
        byte[] S = new byte[M.length + 4];
        System.arraycopy(M, 0, S, 0, M.length);
        System.arraycopy(M_256_2, 0, S, M.length, 4);
        return Base58Utils.encode(S);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Error occured on generating BubiAddress!--" + e.getMessage(), e);
    }
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:31,代码来源:BlockchainKeyPairFactory.java

示例4: constructFingerprintContents

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * Constructs the fingerprint for this condition.
 * <p/>
 * Note: This method is package-private as (opposed to private) for testing purposes.
 */
static final byte[] constructFingerprintContents(final EdDSAPublicKey publicKey) {
  Objects.requireNonNull(publicKey);

  try {
    // Write public publicKey
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DerOutputStream out = new DerOutputStream(baos);
    out.writeTaggedObject(0, publicKey.getA().toByteArray());
    out.close();
    byte[] buffer = baos.toByteArray();

    // Wrap SEQUENCE
    baos = new ByteArrayOutputStream();
    out = new DerOutputStream(baos);
    out.writeEncoded(DerTag.CONSTRUCTED.getTag() + DerTag.SEQUENCE.getTag(), buffer);
    out.close();

    return baos.toByteArray();

  } catch (IOException ioe) {
    throw new UncheckedIOException("DER Encoding Error", ioe);
  }
}
 
开发者ID:interledger,项目名称:java-crypto-conditions,代码行数:29,代码来源:Ed25519Sha256Condition.java

示例5: onPreferenceChange

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
    if (o == null)
        return false;

    String key = (String) o;
    if (key.isEmpty())
        return true;

    Log.d("SettingsActivity", "Trying to set new public key: " + key);
    try {
        new EdDSAPublicKey(new X509EncodedKeySpec(Base64.decode(
                (String) o,
                Base64.DEFAULT
        )));
        Log.d("SettingsActivity", "New key set");
        return true;
    } catch(java.security.spec.InvalidKeySpecException|IllegalArgumentException e) {
        Toast.makeText(mSettingsActivity, R.string.invalid_key_error, Toast.LENGTH_LONG).show();
        Log.d("SettingsActivity", "Key invalid", e);
        return false;
    }
}
 
开发者ID:jplitza,项目名称:DeviceAdministrator,代码行数:24,代码来源:SettingsActivity.java

示例6: fromJavaKey

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 *  Use if SigType is known.
 *
 *  @param pk JAVA key!
 */
public static SigningPublicKey fromJavaKey(PublicKey pk, SigType type)
                          throws GeneralSecurityException {
    switch (type.getBaseAlgorithm()) {
        case DSA:
            return fromJavaKey((DSAPublicKey) pk);
        case EC:
            return fromJavaKey((ECPublicKey) pk, type);
        case EdDSA:
            return fromJavaKey((EdDSAPublicKey) pk, type);
        case RSA:
            return fromJavaKey((RSAPublicKey) pk, type);
        default:
            throw new IllegalArgumentException();
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:21,代码来源:SigUtil.java

示例7: encodePublicKey

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
@Override
public String encodePublicKey(PublicKey publicKey)throws SecurityException {
    try {
        Argument.notNull(publicKey, "publicKey");

        return Encoding.hex(((EdDSAPublicKey) publicKey).getAbyte());
    }
    catch (Exception ex){
        throw new SecurityException("encode public key failed", ex);
    }
}
 
开发者ID:AschPlatform,项目名称:asch-java,代码行数:12,代码来源:DefaultSecurityStrategy.java

示例8: generateKeyPairBySeed

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
public static KeyPair generateKeyPairBySeed(byte[] seed) throws ContractException {
    EdDSAPrivateKeySpec keySpec = new EdDSAPrivateKeySpec(seed, EDDSA_PARAMETER_SPEC);
    EdDSAPrivateKey privateKey = new EdDSAPrivateKey(keySpec);
    EdDSAPublicKey publicKey = new EdDSAPublicKey(new EdDSAPublicKeySpec(privateKey.getAbyte(), EDDSA_PARAMETER_SPEC));

    return new KeyPair(publicKey, privateKey);
}
 
开发者ID:AschPlatform,项目名称:asch-java,代码行数:8,代码来源:Ed25519.java

示例9: verify

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * 对消息签名进行验证
 * @param message 消息内容
 * @param sign 私钥
 * @param publicKey 公钥
 * @return 签名是否正确
 * */
public static boolean verify (byte[] message, byte[] sign, byte[] publicKey) throws InvalidKeyException,SignatureException {

    EdDSAPublicKeySpec spec = new EdDSAPublicKeySpec(publicKey, EdDSANamedCurveTable.getByName(EDDSA_CURVE_TABLE));
    EdDSAPublicKey pKey = new EdDSAPublicKey(spec);
    signature.initVerify(pKey);

    signature.update(message);
    return signature.verify(sign);
}
 
开发者ID:AschPlatform,项目名称:asch-java,代码行数:17,代码来源:Ed25519.java

示例10: KeyManager

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
public KeyManager(_KeyStore store) {
    keySpecs = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512);
    keys = new ArrayList<>();

    String seedBase64 = store.load().orElseGet(() -> {
        KeyPair pair = (new KeyPairGenerator()).generateKeyPair();
        String keyEncoded = MxBase64.encode(pair.getPrivate().getEncoded());
        store.store(keyEncoded);
        return keyEncoded;
    });
    byte[] seed = Base64.getDecoder().decode(seedBase64);
    EdDSAPrivateKeySpec privKeySpec = new EdDSAPrivateKeySpec(seed, keySpecs);
    EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKeySpec.getA(), keySpecs);
    keys.add(new KeyPair(new EdDSAPublicKey(pubKeySpec), new EdDSAPrivateKey(privKeySpec)));
}
 
开发者ID:kamax-io,项目名称:matrix-java-sdk,代码行数:16,代码来源:KeyManager.java

示例11: Ed25519Sha256Fulfillment

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * Constructs an instance of the fulfillment.
 *
 * @param publicKey An {@link EdDSAPublicKey} associated with this fulfillment and its
 *                  corresponding condition.
 * @param signature A byte array containing the signature associated with this fulfillment.
 */
public Ed25519Sha256Fulfillment(final EdDSAPublicKey publicKey, final byte[] signature) {
  super(ED25519_SHA256);

  Objects.requireNonNull(publicKey, "EdDSAPublicKey must not be null!");
  Objects.requireNonNull(signature, "Signature must not be null!");

  this.publicKey = publicKey;
  this.signature = Arrays.copyOf(signature, signature.length);
  this.signatureBase64Url = Base64.getUrlEncoder().encodeToString(signature);
  this.condition = new Ed25519Sha256Condition(publicKey);
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:19,代码来源:Ed25519Sha256Fulfillment.java

示例12: Ed25519Sha256Condition

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * Constructs an instance of the condition.
 *
 * @param key A {@link EdDSAPublicKey} used to create the fingerprint.
 */
public Ed25519Sha256Condition(final EdDSAPublicKey key) {
  super(
      CryptoConditionType.ED25519_SHA256,
      COST,
      hashFingerprintContents(constructFingerprintContents(key))
  );
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:13,代码来源:Ed25519Sha256Condition.java

示例13: constructEdDsaPublicKey

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * Given a public key, construct an EdDSA public key and return it.
 *
 * @param base64UrlEncodedPublicKey A base64Url-encoded String representing the public key bytes
 *                                  for the key to assemble.
 * @return A {@link EdDSAPublicKey}.
 */
public static EdDSAPublicKey constructEdDsaPublicKey(final String base64UrlEncodedPublicKey) {
  final byte[] publicKeyBytes = Base64.getUrlDecoder().decode(base64UrlEncodedPublicKey);
  final EdDSAPublicKeySpec publicKeyspec = new EdDSAPublicKeySpec(
      publicKeyBytes, EdDSANamedCurveTable.getByName(CryptoConditionReader.ED_25519)
  );
  return new EdDSAPublicKey(publicKeyspec);
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:15,代码来源:TestKeyFactory.java

示例14: setup

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * Setup the test.
 */
@BeforeClass
public static void setup() throws Exception {
  Provider bc = new BouncyCastleProvider();
  Security.addProvider(bc);

  final byte[] preimage = "Hello World!".getBytes(Charset.defaultCharset());
  final byte[] prefix = "Ying ".getBytes(Charset.defaultCharset());
  final byte[] message = "Yang".getBytes(Charset.defaultCharset());
  //final byte[] prefixedMessage = "Ying Yang".getBytes(Charset.defaultCharset());

  final MessageDigest sha256Digest = MessageDigest.getInstance("SHA-256");
  final MessageDigest sha512Digest = MessageDigest.getInstance("SHA-512");

  //final byte[] fingerprint = sha256Digest.digest(preimage);

  final KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
  rsaKpg.initialize(new RSAKeyGenParameterSpec(2048, new BigInteger("65537")));
  KeyPair rsaKeyPair = rsaKpg.generateKeyPair();
  Signature rsaSigner = Signature.getInstance("SHA256withRSA/PSS");
  rsaSigner.initSign(rsaKeyPair.getPrivate());
  rsaSigner.update(message);

  net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
  KeyPair edDsaKeyPair = edDsaKpg.generateKeyPair();
  Signature edDsaSigner = new EdDSAEngine(sha512Digest);
  edDsaSigner.initSign(edDsaKeyPair.getPrivate());
  edDsaSigner.update(prefix);
  edDsaSigner.update(message);

  preimageCondition = new PreimageSha256Condition(preimage);
  rsaCondition = new RsaSha256Condition((RSAPublicKey) rsaKeyPair.getPublic());
  ed25519Condition = new Ed25519Sha256Condition((EdDSAPublicKey) edDsaKeyPair.getPublic());
  prefixSha256Condition
      = new PrefixSha256Condition(prefix, 1000, ed25519Condition);
  thresholdCondition = new ThresholdSha256Condition(
      2,
      Lists.newArrayList(preimageCondition, rsaCondition, prefixSha256Condition)
  );

  byte[] rsaSignature = rsaSigner.sign();
  byte[] edDsaSignature = edDsaSigner.sign();
  preimageFulfillment = new PreimageSha256Fulfillment(preimage);
  rsaFulfillment = new RsaSha256Fulfillment((RSAPublicKey) rsaKeyPair.getPublic(), rsaSignature);
  ed25519Fulfillment =
      new Ed25519Sha256Fulfillment((EdDSAPublicKey) edDsaKeyPair.getPublic(), edDsaSignature);
  prefixSha256Fulfillment =
      new PrefixSha256Fulfillment(prefix, 1000, ed25519Fulfillment);
  thresholdFulfillment =
      new ThresholdSha256Fulfillment(
          Lists.newArrayList(rsaCondition),
          Lists.newArrayList(preimageFulfillment, prefixSha256Fulfillment)
      );
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:57,代码来源:CryptoConditionReaderWriterTest.java

示例15: constructEd25519KeyPair

import net.i2p.crypto.eddsa.EdDSAPublicKey; //导入依赖的package包/类
/**
 * Helper method to construct an instance of {@link KeyPair} containing keys for testing purposes.
 *
 * @return An instance of {@link KeyPair}.
 */
protected KeyPair constructEd25519KeyPair() throws InvalidKeySpecException {
  final EdDSANamedCurveSpec edParams = EdDSANamedCurveTable
      .getByName(CryptoConditionReader.ED_25519);
  assert (edParams != null);

  final EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(TEST_PUBKEY, edParams);
  final PublicKey pubKey = new EdDSAPublicKey(pubKeySpec);

  final EdDSAPrivateKeySpec privateKeySpec = new EdDSAPrivateKeySpec(TEST_PRIVKEY, edParams);
  final PrivateKey privKey = new EdDSAPrivateKey(privateKeySpec);

  return new KeyPair(pubKey, privKey);
}
 
开发者ID:hyperledger,项目名称:quilt,代码行数:19,代码来源:Ed25519Sha256ConditionTest.java


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