blob: 56df2bbe0404fed05a8bce3fad2bab8f7db0dc53 [file] [log] [blame]
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package libcore.javax.crypto.spec;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.security.spec.X509EncodedKeySpec;
import tests.security.CipherAsymmetricCryptHelper;
import tests.security.DefaultKeys;
import tests.security.KeyFactoryTest;
public class KeyFactoryTestRSA extends
KeyFactoryTest<RSAPublicKeySpec, RSAPrivateKeySpec> {
@SuppressWarnings("unchecked")
public KeyFactoryTestRSA() {
super("RSA", RSAPublicKeySpec.class, RSAPrivateKeySpec.class);
}
@Override
protected void check(KeyPair keyPair) throws Exception {
new CipherAsymmetricCryptHelper("RSA").test(keyPair);
}
public void testExtraBufferSpace() throws Exception {
PrivateKey privateKey = DefaultKeys.getPrivateKey("RSA");
byte[] encoded = privateKey.getEncoded();
byte[] longBuffer = new byte[encoded.length + 147];
System.arraycopy(encoded, 0, longBuffer, 0, encoded.length);
KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(longBuffer));
PublicKey publicKey = DefaultKeys.getPublicKey("RSA");
encoded = publicKey.getEncoded();
longBuffer = new byte[encoded.length + 147];
System.arraycopy(encoded, 0, longBuffer, 0, encoded.length);
KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(longBuffer));
}
}