8284112: Minor cleanup could be done in javax.crypto

Reviewed-by: wetmore
This commit is contained in:
Mark Powers 2022-04-18 23:48:22 +00:00 committed by Bradford Wetmore
parent 897d6c0dc7
commit 41fc078323
37 changed files with 204 additions and 270 deletions

View File

@ -221,7 +221,7 @@ public class Cipher {
private CipherSpi spi; private CipherSpi spi;
// The transformation // The transformation
private String transformation; private final String transformation;
// Crypto permission representing the maximum allowable cryptographic // Crypto permission representing the maximum allowable cryptographic
// strength that this Cipher object can be used for. (The cryptographic // strength that this Cipher object can be used for. (The cryptographic

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,9 @@
package javax.crypto; package javax.crypto;
import java.io.InputStream;
import java.io.FilterInputStream; import java.io.FilterInputStream;
import java.io.IOException; import java.io.IOException;
import javax.crypto.BadPaddingException; import java.io.InputStream;
import javax.crypto.IllegalBlockSizeException;
/** /**
* A CipherInputStream is composed of an InputStream and a Cipher so * A CipherInputStream is composed of an InputStream and a Cipher so
@ -77,15 +75,15 @@ import javax.crypto.IllegalBlockSizeException;
public class CipherInputStream extends FilterInputStream { public class CipherInputStream extends FilterInputStream {
// the cipher engine to use to process stream data // the cipher engine to use to process stream data
private Cipher cipher; private final Cipher cipher;
// the underlying input stream // the underlying input stream
private InputStream input; private final InputStream input;
/* the buffer holding data that have been read in from the /* the buffer holding data that have been read in from the
underlying stream, but have not been processed by the cipher underlying stream, but have not been processed by the cipher
engine. the size 512 bytes is somewhat randomly chosen */ engine. the size 512 bytes is somewhat randomly chosen */
private byte[] ibuffer = new byte[512]; private final byte[] ibuffer = new byte[512];
// having reached the end of the underlying input stream // having reached the end of the underlying input stream
private boolean done = false; private boolean done = false;
@ -215,7 +213,7 @@ public class CipherInputStream extends FilterInputStream {
if (i == -1) return -1; if (i == -1) return -1;
} }
return ((int) obuffer[ostart++] & 0xff); return ((int) obuffer[ostart++] & 0xff);
}; }
/** /**
* Reads up to <code>b.length</code> bytes of data from this input * Reads up to <code>b.length</code> bytes of data from this input
@ -233,7 +231,7 @@ public class CipherInputStream extends FilterInputStream {
* @see java.io.InputStream#read(byte[], int, int) * @see java.io.InputStream#read(byte[], int, int)
*/ */
@Override @Override
public int read(byte b[]) throws IOException { public int read(byte[] b) throws IOException {
return read(b, 0, b.length); return read(b, 0, b.length);
} }
@ -254,7 +252,7 @@ public class CipherInputStream extends FilterInputStream {
* @see java.io.InputStream#read() * @see java.io.InputStream#read()
*/ */
@Override @Override
public int read(byte b[], int off, int len) throws IOException { public int read(byte[] b, int off, int len) throws IOException {
if (ostart >= ofinish) { if (ostart >= ofinish) {
// we loop for new data as the spec says we are blocking // we loop for new data as the spec says we are blocking
int i = 0; int i = 0;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -71,13 +71,13 @@ import java.io.*;
public class CipherOutputStream extends FilterOutputStream { public class CipherOutputStream extends FilterOutputStream {
// the cipher engine to use to process stream data // the cipher engine to use to process stream data
private Cipher cipher; private final Cipher cipher;
// the underlying output stream // the underlying output stream
private OutputStream output; private final OutputStream output;
/* the buffer holding one byte of incoming data */ /* the buffer holding one byte of incoming data */
private byte[] ibuffer = new byte[1]; private final byte[] ibuffer = new byte[1];
// the buffer holding data ready to be written out // the buffer holding data ready to be written out
private byte[] obuffer = null; private byte[] obuffer = null;
@ -113,7 +113,7 @@ public class CipherOutputStream extends FilterOutputStream {
super(os); super(os);
output = os; output = os;
cipher = c; cipher = c;
}; }
/** /**
* Constructs a CipherOutputStream from an OutputStream without * Constructs a CipherOutputStream from an OutputStream without
@ -149,7 +149,7 @@ public class CipherOutputStream extends FilterOutputStream {
// should never happen; re-throw just in case // should never happen; re-throw just in case
throw new IOException(sbe); throw new IOException(sbe);
} }
}; }
/** /**
* Writes <code>b.length</code> bytes from the specified byte array * Writes <code>b.length</code> bytes from the specified byte array
@ -166,7 +166,7 @@ public class CipherOutputStream extends FilterOutputStream {
* @see javax.crypto.CipherOutputStream#write(byte[], int, int) * @see javax.crypto.CipherOutputStream#write(byte[], int, int)
*/ */
@Override @Override
public void write(byte b[]) throws IOException { public void write(byte[] b) throws IOException {
write(b, 0, b.length); write(b, 0, b.length);
} }
@ -180,7 +180,7 @@ public class CipherOutputStream extends FilterOutputStream {
* @exception IOException if an I/O error occurs. * @exception IOException if an I/O error occurs.
*/ */
@Override @Override
public void write(byte b[], int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
ensureCapacity(len); ensureCapacity(len);
try { try {
int ostored = cipher.update(b, off, len, obuffer); int ostored = cipher.update(b, off, len, obuffer);

View File

@ -25,16 +25,9 @@
package javax.crypto; package javax.crypto;
import java.security.AlgorithmParameters;
import java.security.Key;
import java.security.SecureRandom;
import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;
import java.security.InvalidAlgorithmParameterException;
import java.security.ProviderException;
import java.security.spec.AlgorithmParameterSpec;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
/** /**
* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
@ -540,7 +533,7 @@ public abstract class CipherSpi {
* process ByteBuffers more efficiently than byte arrays. * process ByteBuffers more efficiently than byte arrays.
* *
* @param input the input ByteBuffer * @param input the input ByteBuffer
* @param output the output ByteByffer * @param output the output ByteBuffer
* *
* @return the number of bytes stored in <code>output</code> * @return the number of bytes stored in <code>output</code>
* *
@ -701,7 +694,7 @@ public abstract class CipherSpi {
* process ByteBuffers more efficiently than byte arrays. * process ByteBuffers more efficiently than byte arrays.
* *
* @param input the input ByteBuffer * @param input the input ByteBuffer
* @param output the output ByteByffer * @param output the output ByteBuffer
* *
* @return the number of bytes stored in <code>output</code> * @return the number of bytes stored in <code>output</code>
* *
@ -771,8 +764,9 @@ public abstract class CipherSpi {
byte[] inArray = input.array(); byte[] inArray = input.array();
int inOfs = input.arrayOffset() + inPos; int inOfs = input.arrayOffset() + inPos;
byte[] outArray;
if (a2) { // output has an accessible byte[] if (a2) { // output has an accessible byte[]
byte[] outArray = output.array(); outArray = output.array();
int outPos = output.position(); int outPos = output.position();
int outOfs = output.arrayOffset() + outPos; int outOfs = output.arrayOffset() + outPos;
@ -797,10 +791,7 @@ public abstract class CipherSpi {
// adjust output position manually // adjust output position manually
output.position(outPos + total); output.position(outPos + total);
} }
// adjust input position manually
input.position(inLimit);
} else { // output does not have an accessible byte[] } else { // output does not have an accessible byte[]
byte[] outArray = null;
if (isUpdate) { if (isUpdate) {
outArray = engineUpdate(inArray, inOfs, inLen); outArray = engineUpdate(inArray, inOfs, inLen);
} else { } else {
@ -810,9 +801,9 @@ public abstract class CipherSpi {
output.put(outArray); output.put(outArray);
total = outArray.length; total = outArray.length;
} }
// adjust input position manually
input.position(inLimit);
} }
// adjust input position manually
input.position(inLimit);
} else { // input does not have an accessible byte[] } else { // input does not have an accessible byte[]
// have to assume the worst, since we have no way of determine // have to assume the worst, since we have no way of determine
// if input and output overlaps or not // if input and output overlaps or not
@ -934,7 +925,7 @@ public abstract class CipherSpi {
} }
/** /**
* Continues a multi-part update of the Additional Authentication * Continues a multipart update of the Additional Authentication
* Data (AAD), using a subset of the provided buffer. * Data (AAD), using a subset of the provided buffer.
* <p> * <p>
* Calls to this method provide AAD to the cipher when operating in * Calls to this method provide AAD to the cipher when operating in
@ -964,7 +955,7 @@ public abstract class CipherSpi {
} }
/** /**
* Continues a multi-part update of the Additional Authentication * Continues a multipart update of the Additional Authentication
* Data (AAD). * Data (AAD).
* <p> * <p>
* Calls to this method provide AAD to the cipher when operating in * Calls to this method provide AAD to the cipher when operating in

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
package javax.crypto; package javax.crypto;
import java.io.Serial;
import java.security.*; import java.security.*;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.io.Serializable; import java.io.Serializable;
@ -52,7 +53,7 @@ class CryptoPermission extends java.security.Permission {
@java.io.Serial @java.io.Serial
private static final long serialVersionUID = 8987399626114087514L; private static final long serialVersionUID = 8987399626114087514L;
private String alg; private final String alg;
private int maxKeySize = Integer.MAX_VALUE; // no restriction on maxKeySize private int maxKeySize = Integer.MAX_VALUE; // no restriction on maxKeySize
private String exemptionMechanism = null; private String exemptionMechanism = null;
@SuppressWarnings("serial") // Not statically typed as Serializable @SuppressWarnings("serial") // Not statically typed as Serializable
@ -219,11 +220,9 @@ class CryptoPermission extends java.security.Permission {
* implied by this permission, false otherwise. * implied by this permission, false otherwise.
*/ */
public boolean implies(Permission p) { public boolean implies(Permission p) {
if (!(p instanceof CryptoPermission)) if (!(p instanceof CryptoPermission cp))
return false; return false;
CryptoPermission cp = (CryptoPermission)p;
if ((!alg.equalsIgnoreCase(cp.alg)) && if ((!alg.equalsIgnoreCase(cp.alg)) &&
(!alg.equalsIgnoreCase(ALG_NAME_WILDCARD))) { (!alg.equalsIgnoreCase(ALG_NAME_WILDCARD))) {
return false; return false;
@ -238,9 +237,7 @@ class CryptoPermission extends java.security.Permission {
} }
// check exemptionMechanism. // check exemptionMechanism.
if (impliesExemptionMechanism(cp.exemptionMechanism)) { return impliesExemptionMechanism(cp.exemptionMechanism);
return true;
}
} }
return false; return false;
@ -261,11 +258,9 @@ class CryptoPermission extends java.security.Permission {
if (obj == this) if (obj == this)
return true; return true;
if (!(obj instanceof CryptoPermission)) if (!(obj instanceof CryptoPermission that))
return false; return false;
CryptoPermission that = (CryptoPermission) obj;
if (!(alg.equalsIgnoreCase(that.alg)) || if (!(alg.equalsIgnoreCase(that.alg)) ||
(maxKeySize != that.maxKeySize)) { (maxKeySize != that.maxKeySize)) {
return false; return false;
@ -300,7 +295,7 @@ class CryptoPermission extends java.security.Permission {
/** /**
* There is no action defined for a CryptoPermission * There is no action defined for a CryptoPermission
* onject. * object.
*/ */
public String getActions() public String getActions()
{ {
@ -398,11 +393,7 @@ class CryptoPermission extends java.security.Permission {
return false; return false;
} }
if (this.exemptionMechanism.equals(exemptionMechanism)) { return this.exemptionMechanism.equals(exemptionMechanism);
return true;
}
return false;
} }
private boolean impliesParameterSpec(boolean checkParam, private boolean impliesParameterSpec(boolean checkParam,
@ -442,20 +433,15 @@ class CryptoPermission extends java.security.Permission {
// For classes we don't know, the following // For classes we don't know, the following
// may be the best try. // may be the best try.
if (this.algParamSpec.equals(algParamSpec)) { return this.algParamSpec.equals(algParamSpec);
return true;
}
return false;
} else if (this.checkParam) {
return false;
} else { } else {
return true; return !this.checkParam;
} }
} }
private boolean equalObjects(Object obj1, Object obj2) { private boolean equalObjects(Object obj1, Object obj2) {
if (obj1 == null) { if (obj1 == null) {
return (obj2 == null ? true : false); return (obj2 == null);
} }
return obj1.equals(obj2); return obj1.equals(obj2);
@ -475,16 +461,17 @@ class CryptoPermission extends java.security.Permission {
final class CryptoPermissionCollection extends PermissionCollection final class CryptoPermissionCollection extends PermissionCollection
implements Serializable implements Serializable
{ {
@Serial
private static final long serialVersionUID = -511215555898802763L; private static final long serialVersionUID = -511215555898802763L;
private Vector<Permission> permissions; private final Vector<Permission> permissions;
/** /**
* Creates an empty CryptoPermissionCollection * Creates an empty CryptoPermissionCollection
* object. * object.
*/ */
CryptoPermissionCollection() { CryptoPermissionCollection() {
permissions = new Vector<Permission>(3); permissions = new Vector<>(3);
} }
/** /**
@ -516,11 +503,9 @@ final class CryptoPermissionCollection extends PermissionCollection
* CryptoPermissionCollection, false if not. * CryptoPermissionCollection, false if not.
*/ */
public boolean implies(Permission permission) { public boolean implies(Permission permission) {
if (!(permission instanceof CryptoPermission)) if (!(permission instanceof CryptoPermission cp))
return false; return false;
CryptoPermission cp = (CryptoPermission)permission;
Enumeration<Permission> e = permissions.elements(); Enumeration<Permission> e = permissions.elements();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -143,11 +143,10 @@ implements Serializable {
"object"); "object");
} }
if (!(permission instanceof CryptoPermission)) { if (!(permission instanceof CryptoPermission cryptoPerm)) {
return; return;
} }
CryptoPermission cryptoPerm = (CryptoPermission)permission;
PermissionCollection pc = PermissionCollection pc =
getPermissionCollection(cryptoPerm); getPermissionCollection(cryptoPerm);
pc.add(cryptoPerm); pc.add(cryptoPerm);
@ -156,7 +155,7 @@ implements Serializable {
} }
/** /**
* Checks if this object's PermissionCollection for permissons * Checks if this object's PermissionCollection for permissions
* of the specified permission's algorithm implies the specified * of the specified permission's algorithm implies the specified
* permission. Returns true if the checking succeeded. * permission. Returns true if the checking succeeded.
* *
@ -168,12 +167,10 @@ implements Serializable {
*/ */
@Override @Override
public boolean implies(Permission permission) { public boolean implies(Permission permission) {
if (!(permission instanceof CryptoPermission)) { if (!(permission instanceof CryptoPermission cryptoPerm)) {
return false; return false;
} }
CryptoPermission cryptoPerm = (CryptoPermission)permission;
PermissionCollection pc = PermissionCollection pc =
getPermissionCollection(cryptoPerm.getAlgorithm()); getPermissionCollection(cryptoPerm.getAlgorithm());
@ -299,7 +296,7 @@ implements Serializable {
* Get the minimum of the two given PermissionCollection * Get the minimum of the two given PermissionCollection
* <code>thisPc</code> and <code>thatPc</code>. * <code>thisPc</code> and <code>thatPc</code>.
* *
* @param thisPc the first given PermissionColloection * @param thisPc the first given PermissionCollection
* object. * object.
* *
* @param thatPc the second given PermissionCollection * @param thatPc the second given PermissionCollection

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -66,7 +66,7 @@ import java.lang.reflect.*;
final class CryptoPolicyParser { final class CryptoPolicyParser {
private Vector<GrantEntry> grantEntries; private final Vector<GrantEntry> grantEntries;
// Convenience variables for parsing // Convenience variables for parsing
private StreamTokenizer st; private StreamTokenizer st;
@ -76,7 +76,7 @@ final class CryptoPolicyParser {
* Creates a CryptoPolicyParser object. * Creates a CryptoPolicyParser object.
*/ */
CryptoPolicyParser() { CryptoPolicyParser() {
grantEntries = new Vector<GrantEntry>(); grantEntries = new Vector<>();
} }
/** /**
@ -141,8 +141,7 @@ final class CryptoPolicyParser {
while (lookahead != StreamTokenizer.TT_EOF) { while (lookahead != StreamTokenizer.TT_EOF) {
if (peek("grant")) { if (peek("grant")) {
GrantEntry ge = parseGrantEntry(processedPermissions); GrantEntry ge = parseGrantEntry(processedPermissions);
if (ge != null) grantEntries.addElement(ge);
grantEntries.addElement(ge);
} else { } else {
throw new ParsingException(st.lineno(), "expected grant " + throw new ParsingException(st.lineno(), "expected grant " +
"statement"); "statement");
@ -280,11 +279,11 @@ final class CryptoPolicyParser {
return e; return e;
} }
private static final AlgorithmParameterSpec getInstance(String type, private static AlgorithmParameterSpec getInstance(String type,
Integer[] params) Integer[] params)
throws ParsingException throws ParsingException
{ {
AlgorithmParameterSpec ret = null; AlgorithmParameterSpec ret;
try { try {
Class<?> apsClass = Class.forName(type); Class<?> apsClass = Class.forName(type);
@ -496,7 +495,7 @@ final class CryptoPolicyParser {
exemptionMechanism == null ? "none" : exemptionMechanism; exemptionMechanism == null ? "none" : exemptionMechanism;
if (processedPermissions == null) { if (processedPermissions == null) {
processedPermissions = new Hashtable<String, Vector<String>>(); processedPermissions = new Hashtable<>();
Vector<String> exemptionMechanisms = new Vector<>(1); Vector<String> exemptionMechanisms = new Vector<>(1);
exemptionMechanisms.addElement(thisExemptionMechanism); exemptionMechanisms.addElement(thisExemptionMechanism);
processedPermissions.put(alg, exemptionMechanisms); processedPermissions.put(alg, exemptionMechanisms);
@ -515,7 +514,7 @@ final class CryptoPolicyParser {
return false; return false;
} }
} else { } else {
exemptionMechanisms = new Vector<String>(1); exemptionMechanisms = new Vector<>(1);
} }
exemptionMechanisms.addElement(thisExemptionMechanism); exemptionMechanisms.addElement(thisExemptionMechanism);
@ -553,10 +552,10 @@ final class CryptoPolicyParser {
private static class GrantEntry { private static class GrantEntry {
private Vector<CryptoPermissionEntry> permissionEntries; private final Vector<CryptoPermissionEntry> permissionEntries;
GrantEntry() { GrantEntry() {
permissionEntries = new Vector<CryptoPermissionEntry>(); permissionEntries = new Vector<>();
} }
void add(CryptoPermissionEntry pe) void add(CryptoPermissionEntry pe)
@ -643,11 +642,9 @@ final class CryptoPolicyParser {
if (obj == this) if (obj == this)
return true; return true;
if (!(obj instanceof CryptoPermissionEntry)) if (!(obj instanceof CryptoPermissionEntry that))
return false; return false;
CryptoPermissionEntry that = (CryptoPermissionEntry) obj;
if (this.cryptoPermission == null) { if (this.cryptoPermission == null) {
if (that.cryptoPermission != null) return false; if (that.cryptoPermission != null) return false;
} else { } else {
@ -668,14 +665,10 @@ final class CryptoPolicyParser {
if (this.checkParam != that.checkParam) return false; if (this.checkParam != that.checkParam) return false;
if (this.algParamSpec == null) { if (this.algParamSpec == null) {
if (that.algParamSpec != null) return false; return that.algParamSpec == null;
} else { } else {
if (!this.algParamSpec.equals(that.algParamSpec)) return this.algParamSpec.equals(that.algParamSpec);
return false;
} }
// everything matched -- the 2 objects are equal
return true;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -58,16 +58,16 @@ import sun.security.util.DerOutputStream;
public class EncryptedPrivateKeyInfo { public class EncryptedPrivateKeyInfo {
// the "encryptionAlgorithm" field // the "encryptionAlgorithm" field
private AlgorithmId algid; private final AlgorithmId algid;
// the algorithm name of the encrypted private key // the algorithm name of the encrypted private key
private String keyAlg; private String keyAlg;
// the "encryptedData" field // the "encryptedData" field
private byte[] encryptedData; private final byte[] encryptedData;
// the ASN.1 encoded contents of this class // the ASN.1 encoded contents of this class
private byte[] encoded = null; private byte[] encoded;
/** /**
* Constructs (i.e., parses) an <code>EncryptedPrivateKeyInfo</code> from * Constructs (i.e., parses) an <code>EncryptedPrivateKeyInfo</code> from
@ -124,7 +124,7 @@ public class EncryptedPrivateKeyInfo {
* Java Security Standard Algorithm Names</a> document * Java Security Standard Algorithm Names</a> document
* for information about standard Cipher algorithm names. * for information about standard Cipher algorithm names.
* @param encryptedData encrypted data. The contents of * @param encryptedData encrypted data. The contents of
* <code>encrypedData</code> are copied to protect against subsequent * <code>encryptedData</code> are copied to protect against subsequent
* modification when constructing this object. * modification when constructing this object.
* @exception NullPointerException if <code>algName</code> or * @exception NullPointerException if <code>algName</code> or
* <code>encryptedData</code> is null. * <code>encryptedData</code> is null.
@ -162,10 +162,10 @@ public class EncryptedPrivateKeyInfo {
* @param algParams the algorithm parameters for the encryption * @param algParams the algorithm parameters for the encryption
* algorithm. <code>algParams.getEncoded()</code> should return * algorithm. <code>algParams.getEncoded()</code> should return
* the ASN.1 encoded bytes of the <code>parameters</code> field * the ASN.1 encoded bytes of the <code>parameters</code> field
* of the <code>AlgorithmIdentifer</code> component of the * of the <code>AlgorithmIdentifier</code> component of the
* <code>EncryptedPrivateKeyInfo</code> type. * <code>EncryptedPrivateKeyInfo</code> type.
* @param encryptedData encrypted data. The contents of * @param encryptedData encrypted data. The contents of
* <code>encrypedData</code> are copied to protect against * <code>encryptedData</code> are copied to protect against
* subsequent modification when constructing this object. * subsequent modification when constructing this object.
* @exception NullPointerException if <code>algParams</code> or * @exception NullPointerException if <code>algParams</code> or
* <code>encryptedData</code> is null. * <code>encryptedData</code> is null.
@ -248,7 +248,7 @@ public class EncryptedPrivateKeyInfo {
*/ */
public PKCS8EncodedKeySpec getKeySpec(Cipher cipher) public PKCS8EncodedKeySpec getKeySpec(Cipher cipher)
throws InvalidKeySpecException { throws InvalidKeySpecException {
byte[] encoded = null; byte[] encoded;
try { try {
encoded = cipher.doFinal(encryptedData); encoded = cipher.doFinal(encryptedData);
checkPKCS8Encoding(encoded); checkPKCS8Encoding(encoded);
@ -264,7 +264,7 @@ public class EncryptedPrivateKeyInfo {
private PKCS8EncodedKeySpec getKeySpecImpl(Key decryptKey, private PKCS8EncodedKeySpec getKeySpecImpl(Key decryptKey,
Provider provider) throws NoSuchAlgorithmException, Provider provider) throws NoSuchAlgorithmException,
InvalidKeyException { InvalidKeyException {
byte[] encoded = null; byte[] encoded;
Cipher c; Cipher c;
try { try {
if (provider == null) { if (provider == null) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -52,13 +52,13 @@ import sun.security.jca.GetInstance.Instance;
public class ExemptionMechanism { public class ExemptionMechanism {
// The provider // The provider
private Provider provider; private final Provider provider;
// The provider implementation (delegate) // The provider implementation (delegate)
private ExemptionMechanismSpi exmechSpi; private final ExemptionMechanismSpi exmechSpi;
// The name of the exemption mechanism. // The name of the exemption mechanism.
private String mechanism; private final String mechanism;
// Flag which indicates whether this ExemptionMechanism // Flag which indicates whether this ExemptionMechanism
// result is generated successfully. // result is generated successfully.
@ -118,7 +118,7 @@ public class ExemptionMechanism {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the standard name of the requested exemption * @param algorithm the standard name of the requested exemption
@ -228,7 +228,7 @@ public class ExemptionMechanism {
* @see java.security.Provider * @see java.security.Provider
*/ */
public static final ExemptionMechanism getInstance(String algorithm, public static final ExemptionMechanism getInstance(String algorithm,
Provider provider) throws NoSuchAlgorithmException { Provider provider) throws NoSuchAlgorithmException {
Objects.requireNonNull(algorithm, "null algorithm name"); Objects.requireNonNull(algorithm, "null algorithm name");
Instance instance = JceSecurity.getInstance("ExemptionMechanism", Instance instance = JceSecurity.getInstance("ExemptionMechanism",
ExemptionMechanismSpi.class, algorithm, provider); ExemptionMechanismSpi.class, algorithm, provider);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -90,7 +90,7 @@ final class JceSecurityManager {
CryptoPermission getCryptoPermission(String theAlg) { CryptoPermission getCryptoPermission(String theAlg) {
// Need to convert to uppercase since the crypto perm // Need to convert to uppercase since the crypto perm
// lookup is case sensitive. // lookup is case-sensitive.
final String alg = theAlg.toUpperCase(Locale.ENGLISH); final String alg = theAlg.toUpperCase(Locale.ENGLISH);
// If CryptoAllPermission is granted by default, we return that. // If CryptoAllPermission is granted by default, we return that.
@ -199,7 +199,6 @@ final class JceSecurityManager {
return cp; return cp;
} }
} catch (Exception e) { } catch (Exception e) {
continue;
} }
} }
return defaultPerm; return defaultPerm;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -157,7 +157,7 @@ public class KeyAgreement {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the standard name of the requested key agreement * @param algorithm the standard name of the requested key agreement
@ -186,7 +186,7 @@ public class KeyAgreement {
Iterator<Service> t = services.iterator(); Iterator<Service> t = services.iterator();
while (t.hasNext()) { while (t.hasNext()) {
Service s = t.next(); Service s = t.next();
if (JceSecurity.canUseProvider(s.getProvider()) == false) { if (!JceSecurity.canUseProvider(s.getProvider())) {
continue; continue;
} }
return new KeyAgreement(s, t, algorithm); return new KeyAgreement(s, t, algorithm);
@ -319,12 +319,12 @@ public class KeyAgreement {
} else { } else {
s = serviceIterator.next(); s = serviceIterator.next();
} }
if (JceSecurity.canUseProvider(s.getProvider()) == false) { if (!JceSecurity.canUseProvider(s.getProvider())) {
continue; continue;
} }
try { try {
Object obj = s.newInstance(null); Object obj = s.newInstance(null);
if (obj instanceof KeyAgreementSpi == false) { if (!(obj instanceof KeyAgreementSpi)) {
continue; continue;
} }
spi = (KeyAgreementSpi)obj; spi = (KeyAgreementSpi)obj;
@ -377,10 +377,10 @@ public class KeyAgreement {
s = serviceIterator.next(); s = serviceIterator.next();
} }
// if provider says it does not support this key, ignore it // if provider says it does not support this key, ignore it
if (s.supportsParameter(key) == false) { if (!s.supportsParameter(key)) {
continue; continue;
} }
if (JceSecurity.canUseProvider(s.getProvider()) == false) { if (!JceSecurity.canUseProvider(s.getProvider())) {
continue; continue;
} }
try { try {
@ -563,7 +563,7 @@ public class KeyAgreement {
* @param key the key for this phase. For example, in the case of * @param key the key for this phase. For example, in the case of
* Diffie-Hellman between 2 parties, this would be the other party's * Diffie-Hellman between 2 parties, this would be the other party's
* Diffie-Hellman public key. * Diffie-Hellman public key.
* @param lastPhase flag which indicates whether or not this is the last * @param lastPhase flag which indicates whether this is the last
* phase of this key agreement. * phase of this key agreement.
* *
* @return the (intermediate) key resulting from this phase, or null * @return the (intermediate) key resulting from this phase, or null

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -118,7 +118,7 @@ public abstract class KeyAgreementSpi {
* @param key the key for this phase. For example, in the case of * @param key the key for this phase. For example, in the case of
* Diffie-Hellman between 2 parties, this would be the other party's * Diffie-Hellman between 2 parties, this would be the other party's
* Diffie-Hellman public key. * Diffie-Hellman public key.
* @param lastPhase flag which indicates whether or not this is the last * @param lastPhase flag which indicates whether this is the last
* phase of this key agreement. * phase of this key agreement.
* *
* @return the (intermediate) key resulting from this phase, or null if * @return the (intermediate) key resulting from this phase, or null if

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -218,7 +218,7 @@ public class KeyGenerator {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the standard name of the requested key algorithm. * @param algorithm the standard name of the requested key algorithm.
@ -359,16 +359,15 @@ public class KeyGenerator {
} }
while (serviceIterator.hasNext()) { while (serviceIterator.hasNext()) {
Service s = serviceIterator.next(); Service s = serviceIterator.next();
if (JceSecurity.canUseProvider(s.getProvider()) == false) { if (!JceSecurity.canUseProvider(s.getProvider())) {
continue; continue;
} }
try { try {
Object inst = s.newInstance(null); Object inst = s.newInstance(null);
// ignore non-spis // ignore non-spis
if (inst instanceof KeyGeneratorSpi == false) { if (!(inst instanceof KeyGeneratorSpi spi)) {
continue; continue;
} }
KeyGeneratorSpi spi = (KeyGeneratorSpi)inst;
if (reinit) { if (reinit) {
if (initType == I_SIZE) { if (initType == I_SIZE) {
spi.engineInit(initKeySize, initRandom); spi.engineInit(initKeySize, initRandom);
@ -489,10 +488,7 @@ public class KeyGenerator {
if (failure instanceof InvalidAlgorithmParameterException) { if (failure instanceof InvalidAlgorithmParameterException) {
throw (InvalidAlgorithmParameterException)failure; throw (InvalidAlgorithmParameterException)failure;
} }
if (failure instanceof RuntimeException) { throw (RuntimeException)failure;
throw (RuntimeException)failure;
}
throw new InvalidAlgorithmParameterException("init() failed", failure);
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -156,7 +156,7 @@ public class Mac implements Cloneable {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the standard name of the requested MAC algorithm. * @param algorithm the standard name of the requested MAC algorithm.
@ -182,7 +182,7 @@ public class Mac implements Cloneable {
Iterator<Service> t = services.iterator(); Iterator<Service> t = services.iterator();
while (t.hasNext()) { while (t.hasNext()) {
Service s = t.next(); Service s = t.next();
if (JceSecurity.canUseProvider(s.getProvider()) == false) { if (!JceSecurity.canUseProvider(s.getProvider())) {
continue; continue;
} }
return new Mac(s, t, algorithm); return new Mac(s, t, algorithm);
@ -310,12 +310,12 @@ public class Mac implements Cloneable {
} else { } else {
s = serviceIterator.next(); s = serviceIterator.next();
} }
if (JceSecurity.canUseProvider(s.getProvider()) == false) { if (!JceSecurity.canUseProvider(s.getProvider())) {
continue; continue;
} }
try { try {
Object obj = s.newInstance(null); Object obj = s.newInstance(null);
if (obj instanceof MacSpi == false) { if (!(obj instanceof MacSpi)) {
continue; continue;
} }
spi = (MacSpi)obj; spi = (MacSpi)obj;
@ -354,10 +354,10 @@ public class Mac implements Cloneable {
s = serviceIterator.next(); s = serviceIterator.next();
} }
// if provider says it does not support this key, ignore it // if provider says it does not support this key, ignore it
if (s.supportsParameter(key) == false) { if (!s.supportsParameter(key)) {
continue; continue;
} }
if (JceSecurity.canUseProvider(s.getProvider()) == false) { if (!JceSecurity.canUseProvider(s.getProvider())) {
continue; continue;
} }
try { try {
@ -481,7 +481,7 @@ public class Mac implements Cloneable {
*/ */
public final void update(byte input) throws IllegalStateException { public final void update(byte input) throws IllegalStateException {
chooseFirstProvider(); chooseFirstProvider();
if (initialized == false) { if (!initialized) {
throw new IllegalStateException("MAC not initialized"); throw new IllegalStateException("MAC not initialized");
} }
spi.engineUpdate(input); spi.engineUpdate(input);
@ -497,7 +497,7 @@ public class Mac implements Cloneable {
*/ */
public final void update(byte[] input) throws IllegalStateException { public final void update(byte[] input) throws IllegalStateException {
chooseFirstProvider(); chooseFirstProvider();
if (initialized == false) { if (!initialized) {
throw new IllegalStateException("MAC not initialized"); throw new IllegalStateException("MAC not initialized");
} }
if (input != null) { if (input != null) {
@ -519,7 +519,7 @@ public class Mac implements Cloneable {
public final void update(byte[] input, int offset, int len) public final void update(byte[] input, int offset, int len)
throws IllegalStateException { throws IllegalStateException {
chooseFirstProvider(); chooseFirstProvider();
if (initialized == false) { if (!initialized) {
throw new IllegalStateException("MAC not initialized"); throw new IllegalStateException("MAC not initialized");
} }
@ -544,7 +544,7 @@ public class Mac implements Cloneable {
*/ */
public final void update(ByteBuffer input) { public final void update(ByteBuffer input) {
chooseFirstProvider(); chooseFirstProvider();
if (initialized == false) { if (!initialized) {
throw new IllegalStateException("MAC not initialized"); throw new IllegalStateException("MAC not initialized");
} }
if (input == null) { if (input == null) {
@ -574,7 +574,7 @@ public class Mac implements Cloneable {
*/ */
public final byte[] doFinal() throws IllegalStateException { public final byte[] doFinal() throws IllegalStateException {
chooseFirstProvider(); chooseFirstProvider();
if (initialized == false) { if (!initialized) {
throw new IllegalStateException("MAC not initialized"); throw new IllegalStateException("MAC not initialized");
} }
byte[] mac = spi.engineDoFinal(); byte[] mac = spi.engineDoFinal();
@ -612,7 +612,7 @@ public class Mac implements Cloneable {
throws ShortBufferException, IllegalStateException throws ShortBufferException, IllegalStateException
{ {
chooseFirstProvider(); chooseFirstProvider();
if (initialized == false) { if (!initialized) {
throw new IllegalStateException("MAC not initialized"); throw new IllegalStateException("MAC not initialized");
} }
int macLen = getMacLength(); int macLen = getMacLength();
@ -622,7 +622,6 @@ public class Mac implements Cloneable {
} }
byte[] mac = doFinal(); byte[] mac = doFinal();
System.arraycopy(mac, 0, output, outOffset, macLen); System.arraycopy(mac, 0, output, outOffset, macLen);
return;
} }
/** /**
@ -648,7 +647,7 @@ public class Mac implements Cloneable {
public final byte[] doFinal(byte[] input) throws IllegalStateException public final byte[] doFinal(byte[] input) throws IllegalStateException
{ {
chooseFirstProvider(); chooseFirstProvider();
if (initialized == false) { if (!initialized) {
throw new IllegalStateException("MAC not initialized"); throw new IllegalStateException("MAC not initialized");
} }
update(input); update(input);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -104,7 +104,7 @@ public abstract class MacSpi {
* @since 1.5 * @since 1.5
*/ */
protected void engineUpdate(ByteBuffer input) { protected void engineUpdate(ByteBuffer input) {
if (input.hasRemaining() == false) { if (!input.hasRemaining()) {
return; return;
} }
if (input.hasArray()) { if (input.hasArray()) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -58,8 +58,7 @@ final class NullCipherSpi extends CipherSpi {
} }
protected byte[] engineGetIV() { protected byte[] engineGetIV() {
byte[] x = new byte[8]; return new byte[8];
return x;
} }
protected AlgorithmParameters engineGetParameters() { protected AlgorithmParameters engineGetParameters() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -46,9 +46,8 @@ import java.util.jar.*;
final class ProviderVerifier { final class ProviderVerifier {
// The URL for the JAR file we want to verify. // The URL for the JAR file we want to verify.
private URL jarURL; private final URL jarURL;
private Provider provider; private final boolean savePerms;
private boolean savePerms;
private CryptoPermissions appPerms = null; private CryptoPermissions appPerms = null;
/** /**
@ -72,7 +71,6 @@ final class ProviderVerifier {
*/ */
ProviderVerifier(URL jarURL, Provider provider, boolean savePerms) { ProviderVerifier(URL jarURL, Provider provider, boolean savePerms) {
this.jarURL = jarURL; this.jarURL = jarURL;
this.provider = provider;
this.savePerms = savePerms; this.savePerms = savePerms;
} }
@ -94,7 +92,7 @@ final class ProviderVerifier {
// construct a JAR URL so we can open a JarURLConnection // construct a JAR URL so we can open a JarURLConnection
// for verifying this provider. // for verifying this provider.
final URL url = jarURL.getProtocol().equalsIgnoreCase("jar")? final URL url = jarURL.getProtocol().equalsIgnoreCase("jar")?
jarURL : new URL("jar:" + jarURL.toString() + "!/"); jarURL : new URL("jar:" + jarURL + "!/");
JarFile jf = null; JarFile jf = null;
try { try {
@ -103,19 +101,17 @@ final class ProviderVerifier {
try { try {
@SuppressWarnings("removal") @SuppressWarnings("removal")
var tmp = AccessController.doPrivileged( var tmp = AccessController.doPrivileged(
new PrivilegedExceptionAction<JarFile>() { (PrivilegedExceptionAction<JarFile>) () -> {
public JarFile run() throws Exception { JarURLConnection conn =
JarURLConnection conn = (JarURLConnection) url.openConnection();
(JarURLConnection) url.openConnection(); // You could do some caching here as
// You could do some caching here as // an optimization.
// an optimization. conn.setUseCaches(false);
conn.setUseCaches(false); return conn.getJarFile();
return conn.getJarFile(); });
}
});
jf = tmp; jf = tmp;
} catch (java.security.PrivilegedActionException pae) { } catch (java.security.PrivilegedActionException pae) {
throw new SecurityException("Cannot load " + url.toString(), throw new SecurityException("Cannot load " + url,
pae.getCause()); pae.getCause());
} }
@ -130,8 +126,7 @@ final class ProviderVerifier {
appPerms.load(jf.getInputStream(je)); appPerms.load(jf.getInputStream(je));
} catch (Exception ex) { } catch (Exception ex) {
JarException jex = JarException jex =
new JarException("Cannot load/parse" + new JarException("Cannot load/parse" + jarURL);
jarURL.toString());
jex.initCause(ex); jex.initCause(ex);
throw jex; throw jex;
} }

View File

@ -109,7 +109,7 @@ public class SealedObject implements Serializable {
* *
* @serial * @serial
*/ */
private String sealAlg = null; private final String sealAlg;
/** /**
* The algorithm of the parameters used. * The algorithm of the parameters used.
@ -135,7 +135,7 @@ public class SealedObject implements Serializable {
* encrypted using the given Cipher, which must be fully initialized. * encrypted using the given Cipher, which must be fully initialized.
* *
* <p>Any algorithm parameters that may be used in the encryption * <p>Any algorithm parameters that may be used in the encryption
* operation are stored inside of the new <code>SealedObject</code>. * operation are stored inside the new <code>SealedObject</code>.
* *
* @param object the object to be sealed; can be null. * @param object the object to be sealed; can be null.
* @param c the cipher used to seal the object. * @param c the cipher used to seal the object.
@ -235,9 +235,9 @@ public class SealedObject implements Serializable {
* *
* @return the original object. * @return the original object.
* *
* @exception IOException if an error occurs during de-serialiazation. * @exception IOException if an error occurs during de-serialization.
* @exception ClassNotFoundException if an error occurs during * @exception ClassNotFoundException if an error occurs during
* de-serialiazation. * de-serialization.
* @exception NoSuchAlgorithmException if the algorithm to unseal the * @exception NoSuchAlgorithmException if the algorithm to unseal the
* object is not available. * object is not available.
* @exception InvalidKeyException if the given key cannot be used to unseal * @exception InvalidKeyException if the given key cannot be used to unseal
@ -276,9 +276,9 @@ public class SealedObject implements Serializable {
* @return the original object. * @return the original object.
* *
* @exception NullPointerException if the given cipher is null. * @exception NullPointerException if the given cipher is null.
* @exception IOException if an error occurs during de-serialiazation * @exception IOException if an error occurs during de-serialization
* @exception ClassNotFoundException if an error occurs during * @exception ClassNotFoundException if an error occurs during
* de-serialiazation * de-serialization
* @exception IllegalBlockSizeException if the given cipher is a block * @exception IllegalBlockSizeException if the given cipher is a block
* cipher, no padding has been requested, and the total input length is * cipher, no padding has been requested, and the total input length is
* not a multiple of the cipher's block size * not a multiple of the cipher's block size
@ -291,8 +291,7 @@ public class SealedObject implements Serializable {
BadPaddingException BadPaddingException
{ {
try (ObjectInput a = getExtObjectInputStream(c)) { try (ObjectInput a = getExtObjectInputStream(c)) {
Object obj = a.readObject(); return a.readObject();
return obj;
} }
} }
@ -317,9 +316,9 @@ public class SealedObject implements Serializable {
* *
* @exception IllegalArgumentException if the given provider is null * @exception IllegalArgumentException if the given provider is null
* or empty. * or empty.
* @exception IOException if an error occurs during de-serialiazation. * @exception IOException if an error occurs during de-serialization.
* @exception ClassNotFoundException if an error occurs during * @exception ClassNotFoundException if an error occurs during
* de-serialiazation. * de-serialization.
* @exception NoSuchAlgorithmException if the algorithm to unseal the * @exception NoSuchAlgorithmException if the algorithm to unseal the
* object is not available. * object is not available.
* @exception NoSuchProviderException if the given provider is not * @exception NoSuchProviderException if the given provider is not
@ -408,8 +407,7 @@ public class SealedObject implements Serializable {
} }
try (ObjectInput a = getExtObjectInputStream(c)) { try (ObjectInput a = getExtObjectInputStream(c)) {
Object obj = a.readObject(); return a.readObject();
return obj;
} }
} }
@ -442,7 +440,7 @@ public class SealedObject implements Serializable {
} }
static { static {
SharedSecrets.setJavaxCryptoSealedObjectAccess((obj,c) -> obj.getExtObjectInputStream(c)); SharedSecrets.setJavaxCryptoSealedObjectAccess(SealedObject::getExtObjectInputStream);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -69,5 +69,5 @@ public interface SecretKey extends
*/ */
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
static final long serialVersionUID = -4795878709595146952L; long serialVersionUID = -4795878709595146952L;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -43,7 +43,7 @@ import sun.security.jca.GetInstance.Instance;
* versa. * versa.
* Secret key factories operate only on secret (symmetric) keys. * Secret key factories operate only on secret (symmetric) keys.
* *
* <P> Key factories are bi-directional, i.e., they allow to build an opaque * <P> Key factories are bidirectional, i.e., they allow to build an opaque
* key object from a given key specification (key material), or to retrieve * key object from a given key specification (key material), or to retrieve
* the underlying key material of a key object in a suitable format. * the underlying key material of a key object in a suitable format.
* *
@ -138,7 +138,7 @@ public class SecretKeyFactory {
* {@code jdk.security.provider.preferred} * {@code jdk.security.provider.preferred}
* {@link Security#getProperty(String) Security} property to determine * {@link Security#getProperty(String) Security} property to determine
* the preferred provider order for the specified algorithm. This * the preferred provider order for the specified algorithm. This
* may be different than the order of providers returned by * may be different from the order of providers returned by
* {@link Security#getProviders() Security.getProviders()}. * {@link Security#getProviders() Security.getProviders()}.
* *
* @param algorithm the standard name of the requested secret-key * @param algorithm the standard name of the requested secret-key
@ -280,7 +280,7 @@ public class SecretKeyFactory {
/** /**
* Update the active spi of this class and return the next * Update the active spi of this class and return the next
* implementation for failover. If no more implemenations are * implementation for failover. If no more implementations are
* available, this method returns null. However, the active spi of * available, this method returns null. However, the active spi of
* this class is never set to null. * this class is never set to null.
*/ */
@ -296,15 +296,14 @@ public class SecretKeyFactory {
} }
while (serviceIterator.hasNext()) { while (serviceIterator.hasNext()) {
Service s = serviceIterator.next(); Service s = serviceIterator.next();
if (JceSecurity.canUseProvider(s.getProvider()) == false) { if (!JceSecurity.canUseProvider(s.getProvider())) {
continue; continue;
} }
try { try {
Object obj = s.newInstance(null); Object obj = s.newInstance(null);
if (obj instanceof SecretKeyFactorySpi == false) { if (!(obj instanceof SecretKeyFactorySpi spi)) {
continue; continue;
} }
SecretKeyFactorySpi spi = (SecretKeyFactorySpi)obj;
provider = s.getProvider(); provider = s.getProvider();
this.spi = spi; this.spi = spi;
return spi; return spi;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,7 +48,7 @@ public interface DHPrivateKey extends DHKey, java.security.PrivateKey {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = 2211791113380396553L; long serialVersionUID = 2211791113380396553L;
/** /**
* Returns the private value, <code>x</code>. * Returns the private value, <code>x</code>.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,7 +48,7 @@ public interface DHPublicKey extends DHKey, java.security.PublicKey {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = -6628103563352519193L; long serialVersionUID = -6628103563352519193L;
/** /**
* Returns the public value, <code>y</code>. * Returns the public value, <code>y</code>.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,8 +25,6 @@
package javax.crypto.interfaces; package javax.crypto.interfaces;
import java.math.BigInteger;
/** /**
* The interface to a PBE key. * The interface to a PBE key.
* *
@ -48,7 +46,7 @@ public interface PBEKey extends javax.crypto.SecretKey {
@Deprecated @Deprecated
@SuppressWarnings("serial") @SuppressWarnings("serial")
@java.io.Serial @java.io.Serial
static final long serialVersionUID = -1430015993304333921L; long serialVersionUID = -1430015993304333921L;
/** /**
* Returns the password. * Returns the password.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -37,7 +37,7 @@
* The class itself defines a programming interface to which * The class itself defines a programming interface to which
* applications may write. The implementations themselves may then be * applications may write. The implementations themselves may then be
* written by independent third-party vendors and plugged in * written by independent third-party vendors and plugged in
* seamlessly as needed. Therefore application developers may take * seamlessly as needed. Therefore, application developers may take
* advantage of any number of provider-based implementations without * advantage of any number of provider-based implementations without
* having to add or rewrite code. * having to add or rewrite code.
* *

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -41,7 +41,7 @@ public class DESKeySpec implements java.security.spec.KeySpec {
*/ */
public static final int DES_KEY_LEN = 8; public static final int DES_KEY_LEN = 8;
private byte[] key; private final byte[] key;
/* /*
* Weak/semi-weak keys copied from FIPS 74. * Weak/semi-weak keys copied from FIPS 74.
@ -226,13 +226,14 @@ public class DESKeySpec implements java.security.spec.KeySpec {
} }
for (int i = 0; i < WEAK_KEYS.length; i++) { for (int i = 0; i < WEAK_KEYS.length; i++) {
boolean found = true; boolean found = true;
for (int j = 0; j < DES_KEY_LEN && found == true; j++) { for (int j = 0; j < DES_KEY_LEN; j++) {
if (WEAK_KEYS[i][j] != key[j+offset]) { if (WEAK_KEYS[i][j] != key[j + offset]) {
found = false; found = false;
break;
} }
} }
if (found == true) { if (found) {
return found; return true;
} }
} }
return false; return false;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -41,7 +41,7 @@ public class DESedeKeySpec implements java.security.spec.KeySpec {
*/ */
public static final int DES_EDE_KEY_LEN = 24; public static final int DES_EDE_KEY_LEN = 24;
private byte[] key; private final byte[] key;
/** /**
* Creates a DESedeKeySpec object using the first 24 bytes in * Creates a DESedeKeySpec object using the first 24 bytes in
@ -116,11 +116,8 @@ public class DESedeKeySpec implements java.security.spec.KeySpec {
if (key.length - offset < 24) { if (key.length - offset < 24) {
throw new InvalidKeyException("Wrong key size"); throw new InvalidKeyException("Wrong key size");
} }
if (DESKeySpec.isParityAdjusted(key, offset) == false return DESKeySpec.isParityAdjusted(key, offset)
|| DESKeySpec.isParityAdjusted(key, offset + 8) == false && DESKeySpec.isParityAdjusted(key, offset + 8)
|| DESKeySpec.isParityAdjusted(key, offset + 16) == false) { && DESKeySpec.isParityAdjusted(key, offset + 16);
return false;
}
return true;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package javax.crypto.spec; package javax.crypto.spec;
import java.math.BigInteger;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
/** /**
@ -45,10 +44,10 @@ import java.security.spec.AlgorithmParameterSpec;
public class DHGenParameterSpec implements AlgorithmParameterSpec { public class DHGenParameterSpec implements AlgorithmParameterSpec {
// The size in bits of the prime modulus // The size in bits of the prime modulus
private int primeSize; private final int primeSize;
// The size in bits of the random exponent (private value) // The size in bits of the random exponent (private value)
private int exponentSize; private final int exponentSize;
/** /**
* Constructs a parameter set for the generation of Diffie-Hellman * Constructs a parameter set for the generation of Diffie-Hellman

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -55,13 +55,13 @@ import java.security.spec.AlgorithmParameterSpec;
public class DHParameterSpec implements AlgorithmParameterSpec { public class DHParameterSpec implements AlgorithmParameterSpec {
// The prime modulus // The prime modulus
private BigInteger p; private final BigInteger p;
// The base generator // The base generator
private BigInteger g; private final BigInteger g;
// The size in bits of the random exponent (private value) (optional) // The size in bits of the random exponent (private value) (optional)
private int l; private final int l;
/** /**
* Constructs a parameter set for Diffie-Hellman, using a prime modulus * Constructs a parameter set for Diffie-Hellman, using a prime modulus

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -43,13 +43,13 @@ import java.math.BigInteger;
public class DHPrivateKeySpec implements java.security.spec.KeySpec { public class DHPrivateKeySpec implements java.security.spec.KeySpec {
// The private value // The private value
private BigInteger x; private final BigInteger x;
// The prime modulus // The prime modulus
private BigInteger p; private final BigInteger p;
// The base generator // The base generator
private BigInteger g; private final BigInteger g;
/** /**
* Constructor that takes a private value <code>x</code>, a prime * Constructor that takes a private value <code>x</code>, a prime

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -43,13 +43,13 @@ import java.math.BigInteger;
public class DHPublicKeySpec implements java.security.spec.KeySpec { public class DHPublicKeySpec implements java.security.spec.KeySpec {
// The public value // The public value
private BigInteger y; private final BigInteger y;
// The prime modulus // The prime modulus
private BigInteger p; private final BigInteger p;
// The base generator // The base generator
private BigInteger g; private final BigInteger g;
/** /**
* Constructor that takes a public value <code>y</code>, a prime * Constructor that takes a public value <code>y</code>, a prime

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -39,7 +39,7 @@ import java.security.spec.AlgorithmParameterSpec;
*/ */
public class IvParameterSpec implements AlgorithmParameterSpec { public class IvParameterSpec implements AlgorithmParameterSpec {
private byte[] iv; private final byte[] iv;
/** /**
* Creates an IvParameterSpec object using the bytes in <code>iv</code> * Creates an IvParameterSpec object using the bytes in <code>iv</code>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package javax.crypto.spec; package javax.crypto.spec;
import java.math.BigInteger;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.MGF1ParameterSpec; import java.security.spec.MGF1ParameterSpec;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -39,8 +39,8 @@ import java.security.spec.AlgorithmParameterSpec;
*/ */
public class PBEParameterSpec implements AlgorithmParameterSpec { public class PBEParameterSpec implements AlgorithmParameterSpec {
private byte[] salt; private final byte[] salt;
private int iterationCount; private final int iterationCount;
private AlgorithmParameterSpec paramSpec = null; private AlgorithmParameterSpec paramSpec = null;
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,7 +48,7 @@ package javax.crypto.spec;
*/ */
public class PSource { public class PSource {
private String pSrcName; private final String pSrcName;
/** /**
* Constructs a source of the encoding input P for OAEP * Constructs a source of the encoding input P for OAEP
@ -82,7 +82,7 @@ public class PSource {
*/ */
public static final class PSpecified extends PSource { public static final class PSpecified extends PSource {
private byte[] p = new byte[0]; private final byte[] p;
/** /**
* The encoding input P whose value equals byte[0]. * The encoding input P whose value equals byte[0].

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -45,7 +45,7 @@ import java.security.spec.AlgorithmParameterSpec;
public class RC2ParameterSpec implements AlgorithmParameterSpec { public class RC2ParameterSpec implements AlgorithmParameterSpec {
private byte[] iv = null; private byte[] iv = null;
private int effectiveKeyBits; private final int effectiveKeyBits;
/** /**
* Constructs a parameter set for RC2 from the given effective key size * Constructs a parameter set for RC2 from the given effective key size
@ -135,10 +135,9 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec {
if (obj == this) { if (obj == this) {
return true; return true;
} }
if (!(obj instanceof RC2ParameterSpec)) { if (!(obj instanceof RC2ParameterSpec other)) {
return false; return false;
} }
RC2ParameterSpec other = (RC2ParameterSpec) obj;
return ((effectiveKeyBits == other.effectiveKeyBits) && return ((effectiveKeyBits == other.effectiveKeyBits) &&
java.util.Arrays.equals(iv, other.iv)); java.util.Arrays.equals(iv, other.iv));
@ -155,6 +154,6 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec {
retval += iv[i] * i; retval += iv[i] * i;
} }
} }
return (retval += effectiveKeyBits); return retval + effectiveKeyBits;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -47,9 +47,9 @@ import java.security.spec.AlgorithmParameterSpec;
public class RC5ParameterSpec implements AlgorithmParameterSpec { public class RC5ParameterSpec implements AlgorithmParameterSpec {
private byte[] iv = null; private byte[] iv = null;
private int version; private final int version;
private int rounds; private final int rounds;
private int wordSize; // the word size in bits private final int wordSize; // the word size in bits
/** /**
* Constructs a parameter set for RC5 from the given version, number of * Constructs a parameter set for RC5 from the given version, number of
@ -180,10 +180,9 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec {
if (obj == this) { if (obj == this) {
return true; return true;
} }
if (!(obj instanceof RC5ParameterSpec)) { if (!(obj instanceof RC5ParameterSpec other)) {
return false; return false;
} }
RC5ParameterSpec other = (RC5ParameterSpec) obj;
return ((version == other.version) && return ((version == other.version) &&
(rounds == other.rounds) && (rounds == other.rounds) &&

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,14 +25,13 @@
package javax.crypto.spec; package javax.crypto.spec;
import jdk.internal.access.JavaxCryptoSpecAccess;
import jdk.internal.access.SharedSecrets; import jdk.internal.access.SharedSecrets;
import javax.crypto.SecretKey;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.spec.KeySpec; import java.security.spec.KeySpec;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import javax.crypto.SecretKey;
/** /**
* This class specifies a secret key in a provider-independent fashion. * This class specifies a secret key in a provider-independent fashion.
@ -61,23 +60,18 @@ public class SecretKeySpec implements KeySpec, SecretKey {
* *
* @serial * @serial
*/ */
private byte[] key; private final byte[] key;
/** /**
* The name of the algorithm associated with this key. * The name of the algorithm associated with this key.
* *
* @serial * @serial
*/ */
private String algorithm; private final String algorithm;
static { static {
SharedSecrets.setJavaxCryptoSpecAccess( SharedSecrets.setJavaxCryptoSpecAccess(
new JavaxCryptoSpecAccess() { SecretKeySpec::clear);
@Override
public void clearSecretKeySpec(SecretKeySpec keySpec) {
keySpec.clear();
}
});
} }
/** /**
@ -210,10 +204,9 @@ public class SecretKeySpec implements KeySpec, SecretKey {
retval += this.key[i] * i; retval += this.key[i] * i;
} }
if (this.algorithm.equalsIgnoreCase("TripleDES")) if (this.algorithm.equalsIgnoreCase("TripleDES"))
return (retval ^= "desede".hashCode()); return retval ^ "desede".hashCode();
else else
return (retval ^= return retval ^ this.algorithm.toLowerCase(Locale.ENGLISH).hashCode();
this.algorithm.toLowerCase(Locale.ENGLISH).hashCode());
} }
/** /**