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


Java EdDSAPrivateKey类代码示例

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


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

示例1: generateBubiPriKey

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
/**
 * 根据ED25519算法生成的私钥进行加工,从而得到布比私钥
 * 1.将3字节前缀和1字节版本号0XDA379F01加到P前面,1字节压缩标志添加到P后面即 M=0XDA379F01 + P+0X00
 * 2.将M用SHA256计算两次取前4字节,即Checksum=SHA256(SHA256(M)) 的前4字节
 * 3.将Checksum的前四字节加到M后面,即S=M+Checksum
 * 4.对S进行Base58编码即得到布比私钥。privxxxxxxxxxxxxxxxxxxxxxxxx
 *
 * @param priKey
 * @return
 */
private static String generateBubiPriKey(EdDSAPrivateKey priKey){
    try {
        byte[] priKeyheadArr = Utils.hexToBytes("DA379F01");
        byte[] M = ArrayUtils.addAll(priKeyheadArr, priKey.getSeed());
        byte[] priKeyendArr = Utils.hexToBytes("00");
        M = ArrayUtils.addAll(M, priKeyendArr);
        MessageDigest 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[] M_check = new byte[M.length + 4];
        System.arraycopy(M, 0, M_check, 0, M.length);
        System.arraycopy(m_256_2, 0, M_check, M.length, 4);
        return Base58Utils.encode(M_check);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Error occured on generating BubiAddress!--" + e.getMessage(), e);
    }
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:30,代码来源:BlockchainKeyPairFactory.java

示例2: fromJavaKey

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

示例3: generateKeyPairBySeed

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的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

示例4: KeyManager

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的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

示例5: BuildFromSecrets

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
/**
 * Returns an initialized instance.
 * 
 * if publicKeySource is null it's generated from the privateKey.
 */
public static Ed25519Fulfillment BuildFromSecrets(
        final KeyPayload priv_key_sheed, final MessagePayload message) {
    // TODO:(?) generating the PrivateKey from the key_sheed is "slow". Allow to use a precomputed one?
    final EdDSAPrivateKeySpec privKeySpec = new EdDSAPrivateKeySpec(priv_key_sheed.payload, spec);
    final PrivateKey privKey = new EdDSAPrivateKey(privKeySpec);
    final PublicKey pubKey = _publicKeyFromPrivateKey(privKeySpec);
    return BuildFromSecrets(privKey, pubKey, message);
}
 
开发者ID:mgrand,项目名称:bigchaindb-java-driver,代码行数:14,代码来源:Ed25519Fulfillment.java

示例6: AirPlayAuth

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
/**
 * Create a new instance of AirPlayAuth, to be used to pair/authenticate with an AppleTV for AirPlay
 *
 * @param address   The address of the AppleTV that you retrieve via mdns, eg. 192.168.1.142:7000
 * @param authToken An AuthToken which must be generated via {@code AirPlayAuth.generateNewAuthToken()}.
 * @throws InvalidKeySpecException
 */
public AirPlayAuth(InetSocketAddress address, String authToken) {
    try {
        this.address = address;

        String[] authTokenSplit = authToken.split("@");
        this.clientId = authTokenSplit[0];

        PKCS8EncodedKeySpec encoded = new PKCS8EncodedKeySpec(net.i2p.crypto.eddsa.Utils.hexToBytes(authTokenSplit[1]));
        this.authKey = new EdDSAPrivateKey(encoded);
    } catch (InvalidKeySpecException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:funtax,项目名称:AirPlayAuth,代码行数:21,代码来源:AirPlayAuth.java

示例7: constructEd25519KeyPair

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的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

示例8: build

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
@PostConstruct
public void build() {
    try {
        keySpecs = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512);
        signEngine = new EdDSAEngine(MessageDigest.getInstance(keySpecs.getHashAlgorithm()));
        keys = new ArrayList<>();

        Path privKey = Paths.get(keyCfg.getPath());

        if (!Files.exists(privKey)) {
            KeyPair pair = (new KeyPairGenerator()).generateKeyPair();
            String keyEncoded = Base64.getEncoder().encodeToString(pair.getPrivate().getEncoded());
            FileUtils.writeStringToFile(privKey.toFile(), keyEncoded, StandardCharsets.ISO_8859_1);
            keys.add(pair);
        } else {
            if (Files.isDirectory(privKey)) {
                throw new RuntimeException("Invalid path for private key: " + privKey.toString());
            }

            if (Files.isReadable(privKey)) {
                byte[] seed = Base64.getDecoder().decode(FileUtils.readFileToString(privKey.toFile(), StandardCharsets.ISO_8859_1));
                EdDSAPrivateKeySpec privKeySpec = new EdDSAPrivateKeySpec(seed, keySpecs);
                EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKeySpec.getA(), keySpecs);
                keys.add(new KeyPair(new EdDSAPublicKey(pubKeySpec), new EdDSAPrivateKey(privKeySpec)));
            }
        }
    } catch (NoSuchAlgorithmException | IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:kamax-io,项目名称:mxisd,代码行数:31,代码来源:KeyManager.java

示例9: Signer

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
/**
 * Sign byte-strings using the private key derived from the provided <em>seed</em>.
 *
 * @param seedBytes A <em>seed</em> to create a private key. Not the actual private key. The
 * seed will be transformed and expanded into an Ed25519 private key as described in <a
 * href="https://tools.ietf.org/html/rfc8032#page-13">RFC 8032</a>.
 */
public Signer(byte[] seedBytes) throws InvalidKeyException, SignatureException {
  checkArgument(seedBytes.length >= MIN_SEED_LENGTH, "insufficient private key seed length");

  EdDSAPrivateKeySpec privateSpec = new EdDSAPrivateKeySpec(seedBytes, ED25519_SPEC);
  this.privateKey = new EdDSAPrivateKey(privateSpec);
  this.signer = new EdDSAEngine(RtHashing.newSha512());
  signer.initSign(privateKey);
}
 
开发者ID:int08h,项目名称:nearenough,代码行数:16,代码来源:RtEd25519.java

示例10: loadKey

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
void loadKey() throws IOException, NoSuchAlgorithmException {
	if(!mutable)
		return;
	
	if(keyFile == null) {
		keyFile = Paths.get(".", ".keys", "default.priv");
	}
	
	keyFile = keyFile.toAbsolutePath().normalize();
	
	Path dir = keyFile.getParent();
	
	Files.createDirectories(dir);
	
	// TODO: platform detection
	try {
		Files.setPosixFilePermissions(dir, PosixFilePermissions.fromString("rwx------"));
	} catch (UnsupportedOperationException ex) {
		printErr("Warning: could not restrict access for private key storage directory (filesystem does not support posix permissions?). " + dir.toString() + "\n");
	}
	
	byte[] seed;
	

	if(!Files.exists(keyFile)) {
		seed = SecureRandom.getInstanceStrong().generateSeed(32);
		Files.write(keyFile, Base64.getEncoder().encode(seed), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
		println("Key does not exist, creating... saving at " + keyFile.toString());
	} else {
		seed = Base64.getDecoder().decode(Files.readAllBytes(keyFile));
		if(seed.length != 32) {
			throw new IllegalArgumentException("failed to decode private key, expected 32bytes after base64 decoding");
		}
	}
	
	key = new EdDSAPrivateKey(new EdDSAPrivateKeySpec(seed, GenericStorage.StorageItem.spec));
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:38,代码来源:Put.java

示例11: EdsaSigner

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
public EdsaSigner(byte[] privateKeyBytes) {
	EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512");
	EdDSAPrivateKeySpec privateKeySpec = new EdDSAPrivateKeySpec(privateKeyBytes, spec);
	EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privateKeySpec.getA(), spec);
	publicKey = new EdDSAPublicKey(pubKeySpec);
	privateKey = new EdDSAPrivateKey(privateKeySpec);
}
 
开发者ID:beowulfe,项目名称:HAP-Java,代码行数:8,代码来源:EdsaSigner.java

示例12: signMessage

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
@Override
public byte[] signMessage(byte[] message) {
    try {
        EdDSAEngine sgr = new EdDSAEngine(MessageDigest.getInstance("SHA-512"));
        PrivateKey sKey = new EdDSAPrivateKey(keySpec);
        sgr.initSign(sKey);
        sgr.update(message);
        return sgr.sign();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:13,代码来源:EDKeyPair.java

示例13: toJavaEdDSAKey

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
/**
 *  @return JAVA EdDSA private key!
 *  @since 0.9.15
 */
public static EdDSAPrivateKey toJavaEdDSAKey(SigningPrivateKey pk)
                          throws GeneralSecurityException {
    EdDSAPrivateKey rv;
    synchronized (_EdPrivkeyCache) {
        rv = _EdPrivkeyCache.get(pk);
    }
    if (rv != null)
        return rv;
    rv = cvtToJavaEdDSAKey(pk);
    synchronized (_EdPrivkeyCache) {
        _EdPrivkeyCache.put(pk, rv);
    }
    return rv;
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:19,代码来源:SigUtil.java

示例14: cvtToJavaEdDSAKey

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
/**
 *  @since 0.9.15
 */
private static EdDSAPrivateKey cvtToJavaEdDSAKey(SigningPrivateKey pk)
                          throws GeneralSecurityException {
    try {
        return new EdDSAPrivateKey(new EdDSAPrivateKeySpec(
            pk.getData(), (EdDSAParameterSpec) pk.getType().getParams()));
    } catch (IllegalArgumentException iae) {
        throw new InvalidKeyException(iae);
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:13,代码来源:SigUtil.java

示例15: buildPk

import net.i2p.crypto.eddsa.EdDSAPrivateKey; //导入依赖的package包/类
EdDSAPrivateKey buildPk() {
	return new EdDSAPrivateKey(new EdDSAPrivateKeySpec( GenericStorage.StorageItem.spec, privkeyraw));
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:4,代码来源:Bep44.java


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