74 * 75 * 76 * @since 1.4 77 */ 78 79 public class PSSParameterSpec implements AlgorithmParameterSpec { 80 81 private String mdName = "SHA-1"; 82 private String mgfName = "MGF1"; 83 private AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1; 84 private int saltLen = 20; 85 private int trailerField = 1; 86 87 /** 88 * The PSS parameter set with all default values. 89 * @since 1.5 90 */ 91 public static final PSSParameterSpec DEFAULT = new PSSParameterSpec(); 92 93 /** 94 * Constructs a new <code>PSSParameterSpec</code> as defined in 95 * the PKCS #1 standard using the default values. 96 */ 97 private PSSParameterSpec() { 98 } 99 100 /** 101 * Creates a new <code>PSSParameterSpec</code> as defined in 102 * the PKCS #1 standard using the specified message digest, 103 * mask generation function, parameters for mask generation 104 * function, salt length, and trailer field values. 105 * 106 * @param mdName the algorithm name of the hash function. 107 * @param mgfName the algorithm name of the mask generation 108 * function. 109 * @param mgfSpec the parameters for the mask generation 110 * function. If null is specified, null will be returned by 111 * getMGFParameters(). 112 * @param saltLen the length of salt. 113 * @param trailerField the value of the trailer field. 114 * @exception NullPointerException if <code>mdName</code>, 115 * or <code>mgfName</code> is null. 116 * @exception IllegalArgumentException if <code>saltLen</code> 117 * or <code>trailerField</code> is less than 0. 118 * @since 1.5 119 */ 120 public PSSParameterSpec(String mdName, String mgfName, 121 AlgorithmParameterSpec mgfSpec, 122 int saltLen, int trailerField) { 123 if (mdName == null) { 124 throw new NullPointerException("digest algorithm is null"); 125 } 126 if (mgfName == null) { 127 throw new NullPointerException("mask generation function " + 128 "algorithm is null"); 129 } 130 if (saltLen < 0) { 131 throw new IllegalArgumentException("negative saltLen value: " + 132 saltLen); 133 } 134 if (trailerField < 0) { 135 throw new IllegalArgumentException("negative trailerField: " + 136 trailerField); 137 } 138 this.mdName = mdName; 139 this.mgfName = mgfName; 140 this.mgfSpec = mgfSpec; 141 this.saltLen = saltLen; 142 this.trailerField = trailerField; 143 } 144 145 /** 146 * Creates a new <code>PSSParameterSpec</code> 147 * using the specified salt length and other default values as 148 * defined in PKCS#1. 149 * 150 * @param saltLen the length of salt in bits to be used in PKCS#1 151 * PSS encoding. 152 * @exception IllegalArgumentException if <code>saltLen</code> is 153 * less than 0. 154 */ 155 public PSSParameterSpec(int saltLen) { 156 if (saltLen < 0) { 157 throw new IllegalArgumentException("negative saltLen value: " + 158 saltLen); 159 } 160 this.saltLen = saltLen; 161 } 162 163 /** 164 * Returns the message digest algorithm name. 165 * 166 * @return the message digest algorithm name. 167 * @since 1.5 168 */ 169 public String getDigestAlgorithm() { 170 return mdName; 171 } 172 | 74 * 75 * 76 * @since 1.4 77 */ 78 79 public class PSSParameterSpec implements AlgorithmParameterSpec { 80 81 private String mdName = "SHA-1"; 82 private String mgfName = "MGF1"; 83 private AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1; 84 private int saltLen = 20; 85 private int trailerField = 1; 86 87 /** 88 * The PSS parameter set with all default values. 89 * @since 1.5 90 */ 91 public static final PSSParameterSpec DEFAULT = new PSSParameterSpec(); 92 93 /** 94 * Constructs a new {@code PSSParameterSpec} as defined in 95 * the PKCS #1 standard using the default values. 96 */ 97 private PSSParameterSpec() { 98 } 99 100 /** 101 * Creates a new {@code PSSParameterSpec} as defined in 102 * the PKCS #1 standard using the specified message digest, 103 * mask generation function, parameters for mask generation 104 * function, salt length, and trailer field values. 105 * 106 * @param mdName the algorithm name of the hash function. 107 * @param mgfName the algorithm name of the mask generation 108 * function. 109 * @param mgfSpec the parameters for the mask generation 110 * function. If null is specified, null will be returned by 111 * getMGFParameters(). 112 * @param saltLen the length of salt. 113 * @param trailerField the value of the trailer field. 114 * @exception NullPointerException if {@code mdName}, 115 * or {@code mgfName} is null. 116 * @exception IllegalArgumentException if {@code saltLen} 117 * or {@code trailerField} is less than 0. 118 * @since 1.5 119 */ 120 public PSSParameterSpec(String mdName, String mgfName, 121 AlgorithmParameterSpec mgfSpec, 122 int saltLen, int trailerField) { 123 if (mdName == null) { 124 throw new NullPointerException("digest algorithm is null"); 125 } 126 if (mgfName == null) { 127 throw new NullPointerException("mask generation function " + 128 "algorithm is null"); 129 } 130 if (saltLen < 0) { 131 throw new IllegalArgumentException("negative saltLen value: " + 132 saltLen); 133 } 134 if (trailerField < 0) { 135 throw new IllegalArgumentException("negative trailerField: " + 136 trailerField); 137 } 138 this.mdName = mdName; 139 this.mgfName = mgfName; 140 this.mgfSpec = mgfSpec; 141 this.saltLen = saltLen; 142 this.trailerField = trailerField; 143 } 144 145 /** 146 * Creates a new {@code PSSParameterSpec} 147 * using the specified salt length and other default values as 148 * defined in PKCS#1. 149 * 150 * @param saltLen the length of salt in bits to be used in PKCS#1 151 * PSS encoding. 152 * @exception IllegalArgumentException if {@code saltLen} is 153 * less than 0. 154 */ 155 public PSSParameterSpec(int saltLen) { 156 if (saltLen < 0) { 157 throw new IllegalArgumentException("negative saltLen value: " + 158 saltLen); 159 } 160 this.saltLen = saltLen; 161 } 162 163 /** 164 * Returns the message digest algorithm name. 165 * 166 * @return the message digest algorithm name. 167 * @since 1.5 168 */ 169 public String getDigestAlgorithm() { 170 return mdName; 171 } 172 |