/*
* 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 4894151
* @summary encryption/decryption test for OAEP
* @author Andreas Sterbenz
*/
public class TestOAEP {
// basic test using MD5
try {
throw new Exception("Unexpectedly completed call");
} catch (IllegalBlockSizeException e) {
// ok
}
// basic test using SHA-1
try {
throw new Exception("Unexpectedly completed call");
} catch (IllegalBlockSizeException e) {
// ok
}
// tests alias works
// basic test using SHA-256
try {
throw new Exception("Unexpectedly completed call");
} catch (IllegalBlockSizeException e) {
// ok
}
// 768 bit key too short for OAEP with 64 byte digest
try {
throw new Exception("Unexpectedly completed call");
} catch (InvalidKeyException e) {
// ok
}
Cipher c;
byte[] enc;
byte[] data = new byte[16];
try {
throw new Exception("Unexpectedly completed call");
} catch (NoSuchPaddingException e) {
// ok
}
// cannot "sign" using OAEP
try {
throw new Exception("Unexpectedly completed call");
} catch (InvalidKeyException e) {
// ok
}
// cannot "verify" using OAEP
try {
throw new Exception("Unexpectedly completed call");
} catch (InvalidKeyException e) {
// ok
}
// decryption failure
try {
throw new Exception("Unexpectedly completed call");
} catch (BadPaddingException e) {
// ok
}
// wrong hash length
try {
throw new Exception("Unexpectedly completed call");
} catch (BadPaddingException e) {
// ok
}
/* MD2 not supported with OAEP
// wrong hash value
c = Cipher.getInstance("RSA/ECB/OAEPwithMD2andMGF1Padding", cp);
c.init(Cipher.DECRYPT_MODE, privateKey);
try {
c.doFinal(enc);
throw new Exception("Unexpectedly completed call");
} catch (BadPaddingException e) {
// ok
System.out.println(e);
}
*/
// wrong padding type
try {
throw new Exception("Unexpectedly completed call");
} catch (BadPaddingException e) {
// ok
}
}
byte[] data = new byte[dataLength];
throw new Exception("Data does not match");
}
}
}