summaryrefslogtreecommitdiff
path: root/user/openjdk15/TestECDSA.java
diff options
context:
space:
mode:
authorZach van Rijn <me@zv.io>2022-02-04 23:53:39 +0000
committerZach van Rijn <me@zv.io>2022-11-02 11:12:03 -0500
commit1eb152adb41e758701a2b56a239b89a5da7eb1e6 (patch)
tree1c97037c22e7cf2c50b4263a60c26d40efb88afd /user/openjdk15/TestECDSA.java
parent43f068ae24b0088de194d165482e80cf5197ad92 (diff)
downloadpackages-1eb152adb41e758701a2b56a239b89a5da7eb1e6.tar.gz
packages-1eb152adb41e758701a2b56a239b89a5da7eb1e6.tar.bz2
packages-1eb152adb41e758701a2b56a239b89a5da7eb1e6.tar.xz
packages-1eb152adb41e758701a2b56a239b89a5da7eb1e6.zip
user/openjdk15: new packagezv/openjdk
Diffstat (limited to 'user/openjdk15/TestECDSA.java')
-rw-r--r--user/openjdk15/TestECDSA.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/user/openjdk15/TestECDSA.java b/user/openjdk15/TestECDSA.java
new file mode 100644
index 000000000..abd81d1ce
--- /dev/null
+++ b/user/openjdk15/TestECDSA.java
@@ -0,0 +1,49 @@
+/* TestECDSA -- Ensure ECDSA signatures are working.
+ Copyright (C) 2016 Red Hat, Inc.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as
+published by the Free Software Foundation, either version 3 of the
+License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import java.math.BigInteger;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.Signature;
+
+/**
+ * @test
+ */
+public class TestECDSA {
+
+ public static void main(String[] args) throws Exception {
+ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC");
+ KeyPair key = keyGen.generateKeyPair();
+
+ byte[] data = "This is a string to sign".getBytes("UTF-8");
+
+ Signature dsa = Signature.getInstance("NONEwithECDSA");
+ dsa.initSign(key.getPrivate());
+ dsa.update(data);
+ byte[] sig = dsa.sign();
+ System.out.println("Signature: " + new BigInteger(1, sig).toString(16));
+
+ Signature dsaCheck = Signature.getInstance("NONEwithECDSA");
+ dsaCheck.initVerify(key.getPublic());
+ dsaCheck.update(data);
+ boolean success = dsaCheck.verify(sig);
+ if (!success) {
+ throw new RuntimeException("Test failed. Signature verification error");
+ }
+ System.out.println("Test passed.");
+ }
+}