/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 0000000
* @summary Makes sure that Cipher.doFinal() returns the right number
* of bytes written
* @author Jan Luehe
*/
public class DoFinalReturnLen {
static byte[] dataToEncrypt = {
(byte)0x02, (byte)0xA4, (byte)0x20, (byte)0x87,
(byte)0xB6, (byte)0xC4, (byte)0x54, (byte)0x89,
(byte)0xA2, (byte)0xA4, (byte)0x10, (byte)0x87,
(byte)0xCD, (byte)0x76, (byte)0x43, (byte)0xF0,
(byte)0x72, (byte)0xA4, (byte)0xA0, (byte)0x82,
(byte)0x26, (byte)0xC4, (byte)0x54, (byte)0x19,
(byte)0x09, (byte)0xAC, (byte)0x2A, (byte)0xE7,
(byte)0x1D, (byte)0x74, (byte)0x13, (byte)0x20,
(byte)0xAD, (byte)0xD4, (byte)0xD0, (byte)0x87,
(byte)0xB6, (byte)0xC5, (byte)0x24, (byte)0x89,
(byte)0x02, (byte)0xF4, (byte)0x90, (byte)0x8E,
(byte)0x5D, (byte)0x76, (byte)0x43, (byte)0x2F,
(byte)0x03, (byte)0xAD, (byte)0x20, (byte)0x8C,
(byte)0xB5, (byte)0xC4, (byte)0xA4, (byte)0x39,
(byte)0xD2, (byte)0xA4, (byte)0xE0, (byte)0x87,
(byte)0xCD, (byte)0x56, (byte)0x53, (byte)0x20
};
static byte[] dataToEncryptUneven = {
(byte)0x02, (byte)0xA4, (byte)0x20, (byte)0x87,
(byte)0xB6, (byte)0xC4, (byte)0x54, (byte)0x89,
(byte)0xA2, (byte)0xA4, (byte)0x10, (byte)0x87,
(byte)0xCD, (byte)0x76, (byte)0x43, (byte)0xF0,
(byte)0x72, (byte)0xA4, (byte)0xA0, (byte)0x82,
(byte)0x26, (byte)0xC4, (byte)0x54, (byte)0x19,
(byte)0x09, (byte)0xAC, (byte)0x2A, (byte)0xE7,
(byte)0x1D, (byte)0x74, (byte)0x13, (byte)0x20,
(byte)0xAD, (byte)0xD4, (byte)0xD0, (byte)0x87,
(byte)0xB6, (byte)0xC5, (byte)0x24, (byte)0x89,
(byte)0x02, (byte)0xF4, (byte)0x90, (byte)0x8E,
(byte)0x5D, (byte)0x76, (byte)0x43, (byte)0x2F,
(byte)0x03, (byte)0xAD, (byte)0x20, (byte)0x8C,
(byte)0xB5, (byte)0xC4, (byte)0xA4, (byte)0x39,
(byte)0xD2, (byte)0xA4, (byte)0xE0, (byte)0x87,
(byte)0xCD, (byte)0x56, (byte)0x53, (byte)0x20,
(byte)0x22
};
static byte[] iv = {
(byte)0x03, (byte)0xAD, (byte)0x20, (byte)0x8C,
(byte)0xB5, (byte)0xC4, (byte)0xA4, (byte)0x39
};
byte[] encryptedData = null;
byte[] decryptedData = null;
// Step 0: add providers
}
// Cipher Object
"SunJCE");
byte[] keyData = {
(byte)0x46, (byte)0x19, (byte)0x20, (byte)0x5e,
(byte)0xef, (byte)0x0b, (byte)0x7c, (byte)0x45
};
// Generate secret key
// encrypt data
+ " bytes");
+ " bytes");
// decrypt data
decryptedData, 0);
+ " bytes");
+ " bytes");
int len = 0;
else
for (int i=0; i<len; i++)
if (dataToEncrypt[i] != decryptedData[i])
throw new Exception("Original and recovered data differ");
// decrypt data with exact output buffer length
decryptedData, 0);
+ " bytes");
+ " bytes");
len = 0;
else
for (int i=0; i<len; i++)
if (dataToEncrypt[i] != decryptedData[i])
throw new Exception("Original and recovered data differ");
//
// run the same test for the input data with uneven number of bytes
//
// encrypt data
+ " bytes");
+ " bytes");
// decrypt data
decryptedData, 0);
+ " bytes");
+ " bytes");
len = 0;
else
for (int i=0; i<len; i++)
if (dataToEncryptUneven[i] != decryptedData[i])
throw new Exception("Original and recovered data differ");
// decrypt data with exact output buffer length
decryptedData, 0);
+ " bytes");
+ " bytes");
len = 0;
else
for (int i=0; i<len; i++)
if (dataToEncryptUneven[i] != decryptedData[i])
throw new Exception("Original and recovered data differ");
}
// These methods print out a byte array in a reasonably pretty format.
}
for (int i=0; i < length; i++) {
if (((i%16) == 0) && i != 0) {
hexPrint(i, 8);
for(int j=0; j<16; j++) {
}
}
} else {
}
}
}
}
}
}
}
}