Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ed25519,The value of the signature is wrong #86

Open
imkos opened this issue Jul 23, 2021 · 0 comments
Open

ed25519,The value of the signature is wrong #86

imkos opened this issue Jul 23, 2021 · 0 comments

Comments

@imkos
Copy link

imkos commented Jul 23, 2021

code:

import java.io.BufferedReader;
import java.io.FileReader;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.PrivateKey;
import java.security.Signature;
import java.util.Base64;

import net.i2p.crypto.eddsa.Utils;
import net.i2p.crypto.eddsa.EdDSAEngine;
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec;

public class EdSignTest {
	// ed25519
	final static EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);

	public static void main(String[] args) throws Exception {
        byte[] ZERO_H = Utils.hexToBytes("39e6fb57062449a6a058f7117b3a3ac7e92fd23a6679bc23c882efe2cfb9b520d79a86ac2ebfe10add5e26bead8f6528e8d3b28785b2fe112fe3b78bac27787d");

		String data = "lexar{\"status\": true}BWTbpxar9GPX6yl7H6C5bClxaBFhdxgd1622015270";
		
		//Signature signature = new EdDSAEngine(MessageDigest.getInstance(spec.getHashAlgorithm()));
		EdDSAEngine signature = new EdDSAEngine(MessageDigest.getInstance(spec.getHashAlgorithm()));
		EdDSAPrivateKeySpec privKey = new EdDSAPrivateKeySpec(spec, ZERO_H); //new EdDSAPrivateKeySpec(privSeed, spec);
		PrivateKey sKey = new EdDSAPrivateKey(privKey);
		
		signature.initSign(sKey);
		byte[] msg = data.getBytes(StandardCharsets.UTF_8);
		System.out.println("msg.len:"+ msg.length);
		signature.update(msg);
		byte[] s = signature.sign();
		System.out.println("DATA_HEX : " + Utils.bytesToHex(s));
		String encodedString = Base64.getUrlEncoder().encodeToString(s);

		System.out.println("DATA : " + data);
		System.out.println("SIGN : " + encodedString);
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant