< prev index next >

src/java.base/share/classes/javax/crypto/Mac.java

Print this page

        

*** 52,66 **** * referred to as HMAC. HMAC can be used with any cryptographic hash function, * e.g., MD5 or SHA-1, in combination with a secret shared key. HMAC is * specified in RFC 2104. * * <p> Every implementation of the Java platform is required to support ! * the following standard <code>Mac</code> algorithms: * <ul> ! * <li><tt>HmacMD5</tt></li> ! * <li><tt>HmacSHA1</tt></li> ! * <li><tt>HmacSHA256</tt></li> * </ul> * These algorithms are described in the * <a href="{@docRoot}/../technotes/guides/security/StandardNames.html#Mac"> * Mac section</a> of the * Java Cryptography Architecture Standard Algorithm Name Documentation. --- 52,66 ---- * referred to as HMAC. HMAC can be used with any cryptographic hash function, * e.g., MD5 or SHA-1, in combination with a secret shared key. HMAC is * specified in RFC 2104. * * <p> Every implementation of the Java platform is required to support ! * the following standard {@code Mac} algorithms: * <ul> ! * <li>{@code HmacMD5}</li> ! * <li>{@code HmacSHA1}</li> ! * <li>{@code HmacSHA256}</li> * </ul> * These algorithms are described in the * <a href="{@docRoot}/../technotes/guides/security/StandardNames.html#Mac"> * Mac section</a> of the * Java Cryptography Architecture Standard Algorithm Name Documentation.
*** 125,148 **** this.algorithm = algorithm; lock = new Object(); } /** ! * Returns the algorithm name of this <code>Mac</code> object. * * <p>This is the same name that was specified in one of the ! * <code>getInstance</code> calls that created this ! * <code>Mac</code> object. * ! * @return the algorithm name of this <code>Mac</code> object. */ public final String getAlgorithm() { return this.algorithm; } /** ! * Returns a <code>Mac</code> object that implements the * specified MAC algorithm. * * <p> This method traverses the list of registered security Providers, * starting with the most preferred Provider. * A new Mac object encapsulating the --- 125,148 ---- this.algorithm = algorithm; lock = new Object(); } /** ! * Returns the algorithm name of this {@code Mac} object. * * <p>This is the same name that was specified in one of the ! * {@code getInstance} calls that created this ! * {@code Mac} object. * ! * @return the algorithm name of this {@code Mac} object. */ public final String getAlgorithm() { return this.algorithm; } /** ! * Returns a {@code Mac} object that implements the * specified MAC algorithm. * * <p> This method traverses the list of registered security Providers, * starting with the most preferred Provider. * A new Mac object encapsulating the
*** 156,166 **** * See the Mac section in the <a href= * "{@docRoot}/../technotes/guides/security/StandardNames.html#Mac"> * Java Cryptography Architecture Standard Algorithm Name Documentation</a> * for information about standard algorithm names. * ! * @return the new <code>Mac</code> object. * * @exception NoSuchAlgorithmException if no Provider supports a * MacSpi implementation for the * specified algorithm. * --- 156,166 ---- * See the Mac section in the <a href= * "{@docRoot}/../technotes/guides/security/StandardNames.html#Mac"> * Java Cryptography Architecture Standard Algorithm Name Documentation</a> * for information about standard algorithm names. * ! * @return the new {@code Mac} object. * * @exception NoSuchAlgorithmException if no Provider supports a * MacSpi implementation for the * specified algorithm. *
*** 181,191 **** throw new NoSuchAlgorithmException ("Algorithm " + algorithm + " not available"); } /** ! * Returns a <code>Mac</code> object that implements the * specified MAC algorithm. * * <p> A new Mac object encapsulating the * MacSpi implementation from the specified provider * is returned. The specified provider must be registered --- 181,191 ---- throw new NoSuchAlgorithmException ("Algorithm " + algorithm + " not available"); } /** ! * Returns a {@code Mac} object that implements the * specified MAC algorithm. * * <p> A new Mac object encapsulating the * MacSpi implementation from the specified provider * is returned. The specified provider must be registered
*** 200,219 **** * Java Cryptography Architecture Standard Algorithm Name Documentation</a> * for information about standard algorithm names. * * @param provider the name of the provider. * ! * @return the new <code>Mac</code> object. * * @exception NoSuchAlgorithmException if a MacSpi * implementation for the specified algorithm is not * available from the specified provider. * * @exception NoSuchProviderException if the specified provider is not * registered in the security provider list. * ! * @exception IllegalArgumentException if the <code>provider</code> * is null or empty. * * @see java.security.Provider */ public static final Mac getInstance(String algorithm, String provider) --- 200,219 ---- * Java Cryptography Architecture Standard Algorithm Name Documentation</a> * for information about standard algorithm names. * * @param provider the name of the provider. * ! * @return the new {@code Mac} object. * * @exception NoSuchAlgorithmException if a MacSpi * implementation for the specified algorithm is not * available from the specified provider. * * @exception NoSuchProviderException if the specified provider is not * registered in the security provider list. * ! * @exception IllegalArgumentException if the {@code provider} * is null or empty. * * @see java.security.Provider */ public static final Mac getInstance(String algorithm, String provider)
*** 222,232 **** ("Mac", MacSpi.class, algorithm, provider); return new Mac((MacSpi)instance.impl, instance.provider, algorithm); } /** ! * Returns a <code>Mac</code> object that implements the * specified MAC algorithm. * * <p> A new Mac object encapsulating the * MacSpi implementation from the specified Provider * object is returned. Note that the specified Provider object --- 222,232 ---- ("Mac", MacSpi.class, algorithm, provider); return new Mac((MacSpi)instance.impl, instance.provider, algorithm); } /** ! * Returns a {@code Mac} object that implements the * specified MAC algorithm. * * <p> A new Mac object encapsulating the * MacSpi implementation from the specified Provider * object is returned. Note that the specified Provider object
*** 238,254 **** * Java Cryptography Architecture Standard Algorithm Name Documentation</a> * for information about standard algorithm names. * * @param provider the provider. * ! * @return the new <code>Mac</code> object. * * @exception NoSuchAlgorithmException if a MacSpi * implementation for the specified algorithm is not available * from the specified Provider object. * ! * @exception IllegalArgumentException if the <code>provider</code> * is null. * * @see java.security.Provider */ public static final Mac getInstance(String algorithm, Provider provider) --- 238,254 ---- * Java Cryptography Architecture Standard Algorithm Name Documentation</a> * for information about standard algorithm names. * * @param provider the provider. * ! * @return the new {@code Mac} object. * * @exception NoSuchAlgorithmException if a MacSpi * implementation for the specified algorithm is not available * from the specified Provider object. * ! * @exception IllegalArgumentException if the {@code provider} * is null. * * @see java.security.Provider */ public static final Mac getInstance(String algorithm, Provider provider)
*** 378,390 **** + kName, lastException); } } /** ! * Returns the provider of this <code>Mac</code> object. * ! * @return the provider of this <code>Mac</code> object. */ public final Provider getProvider() { chooseFirstProvider(); return this.provider; } --- 378,390 ---- + kName, lastException); } } /** ! * Returns the provider of this {@code Mac} object. * ! * @return the provider of this {@code Mac} object. */ public final Provider getProvider() { chooseFirstProvider(); return this.provider; }
*** 398,408 **** chooseFirstProvider(); return spi.engineGetMacLength(); } /** ! * Initializes this <code>Mac</code> object with the given key. * * @param key the key. * * @exception InvalidKeyException if the given key is inappropriate for * initializing this MAC. --- 398,408 ---- chooseFirstProvider(); return spi.engineGetMacLength(); } /** ! * Initializes this {@code Mac} object with the given key. * * @param key the key. * * @exception InvalidKeyException if the given key is inappropriate for * initializing this MAC.
*** 424,434 **** this.provider.getName()); } } /** ! * Initializes this <code>Mac</code> object with the given key and * algorithm parameters. * * @param key the key. * @param params the algorithm parameters. * --- 424,434 ---- this.provider.getName()); } } /** ! * Initializes this {@code Mac} object with the given key and * algorithm parameters. * * @param key the key. * @param params the algorithm parameters. *
*** 455,465 **** /** * Processes the given byte. * * @param input the input byte to be processed. * ! * @exception IllegalStateException if this <code>Mac</code> has not been * initialized. */ public final void update(byte input) throws IllegalStateException { chooseFirstProvider(); if (initialized == false) { --- 455,465 ---- /** * Processes the given byte. * * @param input the input byte to be processed. * ! * @exception IllegalStateException if this {@code Mac} has not been * initialized. */ public final void update(byte input) throws IllegalStateException { chooseFirstProvider(); if (initialized == false) {
*** 471,481 **** /** * Processes the given array of bytes. * * @param input the array of bytes to be processed. * ! * @exception IllegalStateException if this <code>Mac</code> has not been * initialized. */ public final void update(byte[] input) throws IllegalStateException { chooseFirstProvider(); if (initialized == false) { --- 471,481 ---- /** * Processes the given array of bytes. * * @param input the array of bytes to be processed. * ! * @exception IllegalStateException if this {@code Mac} has not been * initialized. */ public final void update(byte[] input) throws IllegalStateException { chooseFirstProvider(); if (initialized == false) {
*** 485,502 **** spi.engineUpdate(input, 0, input.length); } } /** ! * Processes the first <code>len</code> bytes in <code>input</code>, ! * starting at <code>offset</code> inclusive. * * @param input the input buffer. ! * @param offset the offset in <code>input</code> where the input starts. * @param len the number of bytes to process. * ! * @exception IllegalStateException if this <code>Mac</code> has not been * initialized. */ public final void update(byte[] input, int offset, int len) throws IllegalStateException { chooseFirstProvider(); --- 485,502 ---- spi.engineUpdate(input, 0, input.length); } } /** ! * Processes the first {@code len} bytes in {@code input}, ! * starting at {@code offset} inclusive. * * @param input the input buffer. ! * @param offset the offset in {@code input} where the input starts. * @param len the number of bytes to process. * ! * @exception IllegalStateException if this {@code Mac} has not been * initialized. */ public final void update(byte[] input, int offset, int len) throws IllegalStateException { chooseFirstProvider();
*** 510,527 **** spi.engineUpdate(input, offset, len); } } /** ! * Processes <code>input.remaining()</code> bytes in the ByteBuffer ! * <code>input</code>, starting at <code>input.position()</code>. * Upon return, the buffer's position will be equal to its limit; * its limit will not have changed. * * @param input the ByteBuffer * ! * @exception IllegalStateException if this <code>Mac</code> has not been * initialized. * @since 1.5 */ public final void update(ByteBuffer input) { chooseFirstProvider(); --- 510,527 ---- spi.engineUpdate(input, offset, len); } } /** ! * Processes {@code input.remaining()} bytes in the ByteBuffer ! * {@code input}, starting at {@code input.position()}. * Upon return, the buffer's position will be equal to its limit; * its limit will not have changed. * * @param input the ByteBuffer * ! * @exception IllegalStateException if this {@code Mac} has not been * initialized. * @since 1.5 */ public final void update(ByteBuffer input) { chooseFirstProvider();
*** 535,558 **** } /** * Finishes the MAC operation. * ! * <p>A call to this method resets this <code>Mac</code> object to the * state it was in when previously initialized via a call to ! * <code>init(Key)</code> or ! * <code>init(Key, AlgorithmParameterSpec)</code>. * That is, the object is reset and available to generate another MAC from ! * the same key, if desired, via new calls to <code>update</code> and ! * <code>doFinal</code>. ! * (In order to reuse this <code>Mac</code> object with a different key, ! * it must be reinitialized via a call to <code>init(Key)</code> or ! * <code>init(Key, AlgorithmParameterSpec)</code>. * * @return the MAC result. * ! * @exception IllegalStateException if this <code>Mac</code> has not been * initialized. */ public final byte[] doFinal() throws IllegalStateException { chooseFirstProvider(); if (initialized == false) { --- 535,558 ---- } /** * Finishes the MAC operation. * ! * <p>A call to this method resets this {@code Mac} object to the * state it was in when previously initialized via a call to ! * {@code init(Key)} or ! * {@code init(Key, AlgorithmParameterSpec)}. * That is, the object is reset and available to generate another MAC from ! * the same key, if desired, via new calls to {@code update} and ! * {@code doFinal}. ! * (In order to reuse this {@code Mac} object with a different key, ! * it must be reinitialized via a call to {@code init(Key)} or ! * {@code init(Key, AlgorithmParameterSpec)}. * * @return the MAC result. * ! * @exception IllegalStateException if this {@code Mac} has not been * initialized. */ public final byte[] doFinal() throws IllegalStateException { chooseFirstProvider(); if (initialized == false) {
*** 564,594 **** } /** * Finishes the MAC operation. * ! * <p>A call to this method resets this <code>Mac</code> object to the * state it was in when previously initialized via a call to ! * <code>init(Key)</code> or ! * <code>init(Key, AlgorithmParameterSpec)</code>. * That is, the object is reset and available to generate another MAC from ! * the same key, if desired, via new calls to <code>update</code> and ! * <code>doFinal</code>. ! * (In order to reuse this <code>Mac</code> object with a different key, ! * it must be reinitialized via a call to <code>init(Key)</code> or ! * <code>init(Key, AlgorithmParameterSpec)</code>. * ! * <p>The MAC result is stored in <code>output</code>, starting at ! * <code>outOffset</code> inclusive. * * @param output the buffer where the MAC result is stored ! * @param outOffset the offset in <code>output</code> where the MAC is * stored * * @exception ShortBufferException if the given output buffer is too small * to hold the result ! * @exception IllegalStateException if this <code>Mac</code> has not been * initialized. */ public final void doFinal(byte[] output, int outOffset) throws ShortBufferException, IllegalStateException { --- 564,594 ---- } /** * Finishes the MAC operation. * ! * <p>A call to this method resets this {@code Mac} object to the * state it was in when previously initialized via a call to ! * {@code init(Key)} or ! * {@code init(Key, AlgorithmParameterSpec)}. * That is, the object is reset and available to generate another MAC from ! * the same key, if desired, via new calls to {@code update} and ! * {@code doFinal}. ! * (In order to reuse this {@code Mac} object with a different key, ! * it must be reinitialized via a call to {@code init(Key)} or ! * {@code init(Key, AlgorithmParameterSpec)}. * ! * <p>The MAC result is stored in {@code output}, starting at ! * {@code outOffset} inclusive. * * @param output the buffer where the MAC result is stored ! * @param outOffset the offset in {@code output} where the MAC is * stored * * @exception ShortBufferException if the given output buffer is too small * to hold the result ! * @exception IllegalStateException if this {@code Mac} has not been * initialized. */ public final void doFinal(byte[] output, int outOffset) throws ShortBufferException, IllegalStateException {
*** 607,631 **** } /** * Processes the given array of bytes and finishes the MAC operation. * ! * <p>A call to this method resets this <code>Mac</code> object to the * state it was in when previously initialized via a call to ! * <code>init(Key)</code> or ! * <code>init(Key, AlgorithmParameterSpec)</code>. * That is, the object is reset and available to generate another MAC from ! * the same key, if desired, via new calls to <code>update</code> and ! * <code>doFinal</code>. ! * (In order to reuse this <code>Mac</code> object with a different key, ! * it must be reinitialized via a call to <code>init(Key)</code> or ! * <code>init(Key, AlgorithmParameterSpec)</code>. * * @param input data in bytes * @return the MAC result. * ! * @exception IllegalStateException if this <code>Mac</code> has not been * initialized. */ public final byte[] doFinal(byte[] input) throws IllegalStateException { chooseFirstProvider(); --- 607,631 ---- } /** * Processes the given array of bytes and finishes the MAC operation. * ! * <p>A call to this method resets this {@code Mac} object to the * state it was in when previously initialized via a call to ! * {@code init(Key)} or ! * {@code init(Key, AlgorithmParameterSpec)}. * That is, the object is reset and available to generate another MAC from ! * the same key, if desired, via new calls to {@code update} and ! * {@code doFinal}. ! * (In order to reuse this {@code Mac} object with a different key, ! * it must be reinitialized via a call to {@code init(Key)} or ! * {@code init(Key, AlgorithmParameterSpec)}. * * @param input data in bytes * @return the MAC result. * ! * @exception IllegalStateException if this {@code Mac} has not been * initialized. */ public final byte[] doFinal(byte[] input) throws IllegalStateException { chooseFirstProvider();
*** 635,656 **** update(input); return doFinal(); } /** ! * Resets this <code>Mac</code> object. * ! * <p>A call to this method resets this <code>Mac</code> object to the * state it was in when previously initialized via a call to ! * <code>init(Key)</code> or ! * <code>init(Key, AlgorithmParameterSpec)</code>. * That is, the object is reset and available to generate another MAC from ! * the same key, if desired, via new calls to <code>update</code> and ! * <code>doFinal</code>. ! * (In order to reuse this <code>Mac</code> object with a different key, ! * it must be reinitialized via a call to <code>init(Key)</code> or ! * <code>init(Key, AlgorithmParameterSpec)</code>. */ public final void reset() { chooseFirstProvider(); spi.engineReset(); } --- 635,656 ---- update(input); return doFinal(); } /** ! * Resets this {@code Mac} object. * ! * <p>A call to this method resets this {@code Mac} object to the * state it was in when previously initialized via a call to ! * {@code init(Key)} or ! * {@code init(Key, AlgorithmParameterSpec)}. * That is, the object is reset and available to generate another MAC from ! * the same key, if desired, via new calls to {@code update} and ! * {@code doFinal}. ! * (In order to reuse this {@code Mac} object with a different key, ! * it must be reinitialized via a call to {@code init(Key)} or ! * {@code init(Key, AlgorithmParameterSpec)}. */ public final void reset() { chooseFirstProvider(); spi.engineReset(); }
*** 659,669 **** * Returns a clone if the provider implementation is cloneable. * * @return a clone if the provider implementation is cloneable. * * @exception CloneNotSupportedException if this is called on a ! * delegate that does not support <code>Cloneable</code>. */ public final Object clone() throws CloneNotSupportedException { chooseFirstProvider(); Mac that = (Mac)super.clone(); that.spi = (MacSpi)this.spi.clone(); --- 659,669 ---- * Returns a clone if the provider implementation is cloneable. * * @return a clone if the provider implementation is cloneable. * * @exception CloneNotSupportedException if this is called on a ! * delegate that does not support {@code Cloneable}. */ public final Object clone() throws CloneNotSupportedException { chooseFirstProvider(); Mac that = (Mac)super.clone(); that.spi = (MacSpi)this.spi.clone();
< prev index next >