diff options
author | Simon Frankenberger <simon@fraho.eu> | 2019-01-28 22:01:51 +0100 |
---|---|---|
committer | Kevin Daudt <kdaudt@alpinelinux.org> | 2019-05-11 16:18:53 +0000 |
commit | 60fc00ff4cf84bb74c7ef84672c294f61aef1ab0 (patch) | |
tree | a8459565ef505b665a26b731b63de503208ada38 /testing/openjdk10/TestECDSA.java | |
parent | aa586529deda3d628c67cf76854522aa8d81eeab (diff) | |
download | aports-60fc00ff4cf84bb74c7ef84672c294f61aef1ab0.tar.bz2 aports-60fc00ff4cf84bb74c7ef84672c294f61aef1ab0.tar.xz |
testing/openjdk10: New aport
Diffstat (limited to 'testing/openjdk10/TestECDSA.java')
-rw-r--r-- | testing/openjdk10/TestECDSA.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/testing/openjdk10/TestECDSA.java b/testing/openjdk10/TestECDSA.java new file mode 100644 index 0000000000..abd81d1ced --- /dev/null +++ b/testing/openjdk10/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."); + } +} |