1 /*
2 * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
410 sig = signature;
411 } else {
412 sig = decodeSignature(signature);
413 }
414
415 try {
416 return verifySignedDigest(sig, getDigestValue(), w, encodedParams);
417 } catch (GeneralSecurityException e) {
418 throw new SignatureException("Could not verify signature", e);
419 }
420 }
421
422 // set parameter, not supported. See JCA doc
423 @Override
424 @Deprecated
425 protected void engineSetParameter(String param, Object value)
426 throws InvalidParameterException {
427 throw new UnsupportedOperationException("setParameter() not supported");
428 }
429
430 // get parameter, not supported. See JCA doc
431 @Override
432 @Deprecated
433 protected Object engineGetParameter(String param)
434 throws InvalidParameterException {
435 throw new UnsupportedOperationException("getParameter() not supported");
436 }
437
438 // Convert the concatenation of R and S into their DER encoding
439 private byte[] encodeSignature(byte[] signature) throws SignatureException {
440
441 try {
442
443 int n = signature.length >> 1;
444 byte[] bytes = new byte[n];
445 System.arraycopy(signature, 0, bytes, 0, n);
446 BigInteger r = new BigInteger(1, bytes);
447 System.arraycopy(signature, n, bytes, 0, n);
448 BigInteger s = new BigInteger(1, bytes);
449
450 DerOutputStream out = new DerOutputStream(signature.length + 10);
451 out.putInteger(r);
452 out.putInteger(s);
453 DerValue result =
454 new DerValue(DerValue.tag_Sequence, out.toByteArray());
455
|
1 /*
2 * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
410 sig = signature;
411 } else {
412 sig = decodeSignature(signature);
413 }
414
415 try {
416 return verifySignedDigest(sig, getDigestValue(), w, encodedParams);
417 } catch (GeneralSecurityException e) {
418 throw new SignatureException("Could not verify signature", e);
419 }
420 }
421
422 // set parameter, not supported. See JCA doc
423 @Override
424 @Deprecated
425 protected void engineSetParameter(String param, Object value)
426 throws InvalidParameterException {
427 throw new UnsupportedOperationException("setParameter() not supported");
428 }
429
430 @Override
431 protected void engineSetParameter(AlgorithmParameterSpec params)
432 throws InvalidAlgorithmParameterException {
433 if (params != null) {
434 throw new InvalidAlgorithmParameterException("No parameter accepted");
435 }
436 }
437
438 // get parameter, not supported. See JCA doc
439 @Override
440 @Deprecated
441 protected Object engineGetParameter(String param)
442 throws InvalidParameterException {
443 throw new UnsupportedOperationException("getParameter() not supported");
444 }
445
446 @Override
447 protected AlgorithmParameters engineGetParameters() {
448 return null;
449 }
450
451 // Convert the concatenation of R and S into their DER encoding
452 private byte[] encodeSignature(byte[] signature) throws SignatureException {
453
454 try {
455
456 int n = signature.length >> 1;
457 byte[] bytes = new byte[n];
458 System.arraycopy(signature, 0, bytes, 0, n);
459 BigInteger r = new BigInteger(1, bytes);
460 System.arraycopy(signature, n, bytes, 0, n);
461 BigInteger s = new BigInteger(1, bytes);
462
463 DerOutputStream out = new DerOutputStream(signature.length + 10);
464 out.putInteger(r);
465 out.putInteger(s);
466 DerValue result =
467 new DerValue(DerValue.tag_Sequence, out.toByteArray());
468
|