本文整理汇总了Java中net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec类的典型用法代码示例。如果您正苦于以下问题:Java EdDSAPrivateKeySpec类的具体用法?Java EdDSAPrivateKeySpec怎么用?Java EdDSAPrivateKeySpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EdDSAPrivateKeySpec类属于net.i2p.crypto.eddsa.spec包,在下文中一共展示了EdDSAPrivateKeySpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSign
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的package包/类
@Test
public void testSign() throws Exception {
//Signature sgr = Signature.getInstance("EdDSA", "I2P");
Signature sgr = new EdDSAEngine(MessageDigest.getInstance("SHA-512"));
EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512");
for (Ed25519TestVectors.TestTuple testCase : Ed25519TestVectors.testCases) {
EdDSAPrivateKeySpec privKey = new EdDSAPrivateKeySpec(testCase.seed, spec);
PrivateKey sKey = new EdDSAPrivateKey(privKey);
sgr.initSign(sKey);
sgr.update(testCase.message);
assertThat("Test case " + testCase.caseNum + " failed",
sgr.sign(), is(equalTo(testCase.sig)));
}
}
示例2: generateKeyPairBySeed
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的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);
}
示例3: KeyManager
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的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)));
}
示例4: BuildFromSecrets
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的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);
}
示例5: constructEd25519KeyPair
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的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);
}
示例6: build
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的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);
}
}
示例7: Signer
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的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);
}
示例8: EdDSAPrivateKey
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的package包/类
public EdDSAPrivateKey(EdDSAPrivateKeySpec spec) {
this.seed = spec.getSeed();
this.h = spec.getH();
this.a = spec.geta();
this.A = spec.getA();
this.Abyte = this.A.toByteArray();
this.edDsaSpec = spec.getParams();
}
示例9: engineGeneratePrivate
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
throws InvalidKeySpecException {
if (keySpec instanceof EdDSAPrivateKeySpec) {
return new EdDSAPrivateKey((EdDSAPrivateKeySpec) keySpec);
}
if (keySpec instanceof PKCS8EncodedKeySpec) {
return new EdDSAPrivateKey((PKCS8EncodedKeySpec) keySpec);
}
throw new InvalidKeySpecException("key spec not recognised: " + keySpec.getClass());
}
示例10: loadKey
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的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));
}
示例11: EdsaSigner
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的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);
}
示例12: generateKeyPair
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的package包/类
public KeyPair generateKeyPair() {
if (!initialized)
initialize(DEFAULT_KEYSIZE, new SecureRandom());
byte[] seed = new byte[edParams.getCurve().getField().getb()/8];
random.nextBytes(seed);
EdDSAPrivateKeySpec privKey = new EdDSAPrivateKeySpec(seed, edParams);
EdDSAPublicKeySpec pubKey = new EdDSAPublicKeySpec(privKey.getA(), edParams);
return new KeyPair(new EdDSAPublicKey(pubKey), new EdDSAPrivateKey(privKey));
}
示例13: cvtToJavaEdDSAKey
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的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);
}
}
示例14: engineGeneratePrivate
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
throws InvalidKeySpecException {
if (keySpec instanceof EdDSAPrivateKeySpec) {
return new EdDSAPrivateKey((EdDSAPrivateKeySpec) keySpec);
}
throw new InvalidKeySpecException("key spec not recognised");
}
示例15: generateKeyPair
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; //导入依赖的package包/类
public KeyPair generateKeyPair() {
if (!initialized)
initialize(DEFAULT_STRENGTH, RandomSource.getInstance());
byte[] seed = new byte[edParams.getCurve().getField().getb()/8];
random.nextBytes(seed);
EdDSAPrivateKeySpec privKey = new EdDSAPrivateKeySpec(seed, edParams);
EdDSAPublicKeySpec pubKey = new EdDSAPublicKeySpec(privKey.getA(), edParams);
return new KeyPair(new EdDSAPublicKey(pubKey), new EdDSAPrivateKey(privKey));
}