{
c1.init(Cipher.DECRYPT_MODE, privKey);
}
catch (InvalidKeyException e)
{
throw new PGPException("error setting asymmetric cipher", e);
}
if (keyAlgorithm == PGPPublicKey.RSA_ENCRYPT
|| keyAlgorithm == PGPPublicKey.RSA_GENERAL)
{
byte[] bi = secKeyData[0].toByteArray();
if (bi[0] == 0)
{
c1.update(bi, 1, bi.length - 1);
}
else
{
c1.update(bi);
}
}
else
{
ElGamalKey k = (ElGamalKey)privKey;
int size = (k.getParameters().getP().bitLength() + 7) / 8;
byte[] tmp = new byte[size];
byte[] bi = secKeyData[0].toByteArray();
if (bi.length > size)
{
c1.update(bi, 1, bi.length - 1);
}
else
{
System.arraycopy(bi, 0, tmp, tmp.length - bi.length, bi.length);
c1.update(tmp);
}
bi = secKeyData[1].toByteArray();
for (int i = 0; i != tmp.length; i++)
{
tmp[i] = 0;
}
if (bi.length > size)
{
c1.update(bi, 1, bi.length - 1);
}
else
{
System.arraycopy(bi, 0, tmp, tmp.length - bi.length, bi.length);
c1.update(tmp);
}
}
byte[] plain;
try
{
plain = c1.doFinal();
}
catch (Exception e)
{
throw new PGPException("exception decrypting session data", e);
}
return plain;
}