throws PGPException, NoSuchProviderException
{
byte[] rawKeyData = key.extractKeyData(oldPassPhrase, provider);
int s2kUsage = key.secret.getS2KUsage();
byte[] iv = null;
S2K s2k = null;
byte[] keyData = null;
if (newEncAlgorithm == SymmetricKeyAlgorithmTags.NULL)
{
s2kUsage = SecretKeyPacket.USAGE_NONE;
if (key.secret.getS2KUsage() == SecretKeyPacket.USAGE_SHA1) // SHA-1 hash, need to rewrite checksum
{
keyData = new byte[rawKeyData.length - 18];
System.arraycopy(rawKeyData, 0, keyData, 0, keyData.length - 2);
byte[] check = checksum(false, keyData, keyData.length - 2);
keyData[keyData.length - 2] = check[0];
keyData[keyData.length - 1] = check[1];
}
else
{
keyData = rawKeyData;
}
}
else
{
Cipher c = null;
String cName = PGPUtil.getSymmetricCipherName(newEncAlgorithm);
try
{
c = Cipher.getInstance(cName + "/CFB/NoPadding", provider);
}
catch (NoSuchProviderException e)
{
throw e;
}
catch (Exception e)
{
throw new PGPException("Exception creating cipher", e);
}
iv = new byte[8];
rand.nextBytes(iv);
s2k = new S2K(HashAlgorithmTags.SHA1, iv, 0x60);
try
{
SecretKey sKey = PGPUtil.makeKeyFromPassPhrase(newEncAlgorithm, s2k, newPassPhrase, provider);