Bitcoin Forum

Bitcoin => BitcoinJ => Topic started by: Amitabh S on October 01, 2013, 10:21:26 AM



Title: Bitcoinj - error when signing message with UTF8 encoding
Post by: Amitabh S on October 01, 2013, 10:21:26 AM
I have tried the latest build of bitcoinj and get error signing messages containing non-ascii characters. This problem also occurs with older versions.

Here is the string.

C'est par mon ordre et pour le bien de l'Etat que le porteur du présent a fait ce qu'il a fait.

This is the default string on brainwallet verify tab (http://brainwallet.org/#verify)

When I use the com.google.bitcoin.core.ECKey.signMessage() method to try to sign this message. I get an exception "array index out of bound". This works nicely if the string contains only ASCII characters. So if we remove the é from the above string, things work fine.

Hope this is fixed soon.

Cheers!




Title: Re: Bitcoinj - error when signing message with UTF8 encoding
Post by: Mike Hearn on October 02, 2013, 08:41:25 AM
D'oh, schoolboy error, sorry. I just pushed a fix to git master.


Title: Re: Bitcoinj - error when signing message with UTF8 encoding
Post by: Amitabh S on October 07, 2013, 11:39:50 AM
D'oh, schoolboy error, sorry. I just pushed a fix to git master.

Thanks! BTW can you put a compiled jar somewhere? I could not compile it with Maven (some errors I cannot remember... will post later).

PS lots of people dislike maven. Why are so many good projects hampered by Maven (http://www.jillesvangurp.com/2009/10/16/maven-good-ideas-gone-wrong/)?


Title: Re: Bitcoinj - error when signing message with UTF8 encoding
Post by: Mike Hearn on October 07, 2013, 12:02:01 PM
Maven isn't great, but it handles resolution of dependencies and is reasonably standard - lots of IDEs and tools support it.

If you were having issues with the unit tests try

mvn install -DskipTests=true

or something similar. Or just open it up with your IDE and let it handle things.

If we provided compiled JARs you'd have to grab all the dependencies by hand, which is painful.


Title: Re: Bitcoinj - error when signing message with UTF8 encoding
Post by: Amitabh S on October 07, 2013, 03:35:14 PM
This is the output on compile using mvn install -DskipTests=true

Code:
INFO] ------------------------------------------------------------------------
INFO] Reactor Summary:
INFO]
INFO] bitcoinj Parent ................................... SUCCESS [0.225s]
INFO] bitcoinj .......................................... FAILURE [12.582s]
INFO] bitcoinj Examples ................................. SKIPPED
INFO] bitcoinj Tools .................................... SKIPPED
INFO] ------------------------------------------------------------------------
INFO] BUILD FAILURE
INFO] ------------------------------------------------------------------------
INFO] Total time: 12.976s
INFO] Finished at: Mon Oct 07 21:03:52 IST 2013
INFO] Final Memory: 10M/62M
INFO] ------------------------------------------------------------------------
ERROR] Failed to execute goal org.apache.maven.plugins:maven-source-plugin:2.1.2:jar-no-fork (attach-sources) on project bitcoinj: Execution attach-sources of goal org.apache.maven.plugins:maven-source-plugin:2.1.2:jar-no-fork failed: Negative time -> [Help 1]

Should this work in some IDE (and which one)? (I currently only use notepad++)


If we provided compiled JARs you'd have to grab all the dependencies by hand, which is painful.

I think I can manage with the dependencies :P


Title: Re: Bitcoinj - error when signing message with UTF8 encoding
Post by: Mike Hearn on October 07, 2013, 05:13:01 PM
Negative time?! I've never seen that error before, you're on Windows? If so, what JDK version and what filing system are you using? From a quick Googling it seems that this error can happen if you have files in your directory tree with timestamps before the UNIX epoch (1970) which obviously should never happen on a working setup.

I don't recommend doing anything in Java with just a text editor. The language is awkwardly verbose. A good IDE like IntelliJ will hide most of the uglyness from you and make it bearable. IntelliJ is free so you can go grab it and then load it up. If you tell it where to find your Maven install, it should work things out for you.

If you want to download the JARs by hand, go ahead, look inside the pom file to see what the library depends on. But it'll take a while. I'd recommend figuring out why Maven thinks time is going backwards instead. I suspect some clock issue or a filing system that doesn't store timestamps properly.



Title: Re: Bitcoinj - error when signing message with UTF8 encoding
Post by: Amitabh S on October 07, 2013, 06:18:38 PM
Negative time?! I've never seen that error before, you're on Windows? If so, what JDK version and what filing system are you using? From a quick Googling it seems that this error can happen if you have files in your directory tree with timestamps before the UNIX epoch (1970) which obviously should never happen on a working setup.

I don't recommend doing anything in Java with just a text editor. The language is awkwardly verbose. A good IDE like IntelliJ will hide most of the uglyness from you and make it bearable. IntelliJ is free so you can go grab it and then load it up. If you tell it where to find your Maven install, it should work things out for you.

If you want to download the JARs by hand, go ahead, look inside the pom file to see what the library depends on. But it'll take a while. I'd recommend figuring out why Maven thinks time is going backwards instead. I suspect some clock issue or a filing system that doesn't store timestamps properly.



I use windows 7 Professional 64 bit. Time has been correct.

About the IDE, I actually don't use Java directly but usually write in Scala (I consider Scala a wrapper for Java). With Scala, notepad++ is more than enough unless the project is very large.

I will try to recompile on a different PC tomorrow at work, where I have 32 bit Win 7. I have all the dependencies for the earlier version 0.10, so they should just work anyway.


Title: Re: Bitcoinj - error when signing message with UTF8 encoding
Post by: Mike Hearn on October 07, 2013, 06:27:29 PM
OK, great. Let me know how you get on. If you figure out a solution for the negative time thing, that'd also be useful to know. I'd start by checking the file times in the source tree to make sure none are unrealistically early.


Title: Re: Bitcoinj - error when signing message with UTF8 encoding
Post by: Amitabh S on October 07, 2013, 08:08:06 PM
Hey Mike! Thanks for your help. The -DskipTests=true helped a lot :P

It was my mistake (and possibly a bug in google code repository)
I had download a zip from the repository instead of using git clone.

When I did using git clone, it worked perfectly.


Title: Re: Bitcoinj - error when signing message with UTF8 encoding
Post by: Mike Hearn on October 08, 2013, 02:51:14 PM
A bug in Google Code would not surprise me, unfortunately.