/* * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code 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 General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
privatestaticfinal Test[] tests = { new Test(SigAlg.SHA1withDSA, KeyAlg.DSA, Provider.Default, 1024), new Test(SigAlg.MD2withRSA, KeyAlg.RSA, Provider.Default), new Test(SigAlg.MD5withRSA, KeyAlg.RSA, Provider.Default), new Test(SigAlg.SHA3_224withRSA, KeyAlg.RSA, Provider.Default), new Test(SigAlg.SHA3_256withRSA, KeyAlg.RSA, Provider.Default), new Test(SigAlg.SHA3_384withRSA, KeyAlg.RSA, Provider.Default), new Test(SigAlg.SHA3_512withRSA, KeyAlg.RSA, Provider.Default), new Test(SigAlg.SHA1withDSA, KeyAlg.DSA, Provider.Sun, 1024), new Test(SigAlg.SHA224withDSA, KeyAlg.DSA, Provider.Sun, 2048), new Test(SigAlg.SHA256withDSA, KeyAlg.DSA, Provider.Sun, 2048),
};
privatestaticfinal String str = "to-be-signed"; privatestaticfinalint N = 3;
publicstaticvoid main(String argv[]) { boolean result = Arrays.stream(tests).allMatch((test) -> runTest(test));
result &= runTestPSS(2048); if (result) {
System.out.println("All tests passed");
} else { thrownew RuntimeException("Some tests failed");
}
}
if (Arrays.equals(pubKeys[j].getEncoded(),
anotherPubKeys[j].getEncoded())) {
System.out.println("Failed: it should not get "
+ "the same pair of public key"); returnfalse;
}
}
// Create a chain of signed objects
SignedObject[] objects = new SignedObject[N];
objects[0] = new SignedObject(str, privKeys[0], signature); for (int j = 1; j < N; j++) {
objects[j] = new SignedObject(objects[j - 1], privKeys[j],
signature);
}
// Verify the chain int n = objects.length - 1;
SignedObject object = objects[n]; do { if (!object.verify(pubKeys[n], signature)) {
System.out.println("Failed: verification failed, n = " + n); returnfalse;
} if (object.verify(anotherPubKeys[n], signature)) {
System.out.println("Failed: verification should not "
+ "succeed with wrong public key, n = " + n); returnfalse;
}
object = (SignedObject) object.getObject();
n--;
} while (n > 0);
System.out.println("signed data: " + object.getObject()); if (!str.equals(object.getObject())) {
System.out.println("Failed: signed data is not equal to "
+ "original one"); returnfalse;
}
System.out.println("Test passed"); returntrue;
} catch (NoSuchProviderException nspe) { if (test.provider == Provider.SunMSCAPI
&& !System.getProperty("os.name").startsWith("Windows")) {
System.out.println("SunMSCAPI is available only on Windows: "
+ nspe); returntrue;
}
System.out.println("Unexpected exception: " + nspe); returnfalse;
} catch (Exception e) {
System.out.println("Unexpected exception: " + e);
e.printStackTrace(System.out); returnfalse;
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.