2

我有一个解密数据的骆驼路线,如下所示:

....

val encryptedTextBC = "-----BEGIN PGP MESSAGE-----\nVersion: BCPG v1.46\n\nhQEMA6OBb7KaTXc9AQgAngV5foRhtuySGXiRfaSOoGIFHUMc9lPG93AOnCaO4Ten\nuHPIHNGeeYp0+0u7d4dVSPeGR7nMDoELHjHXxwIe4zAcdglSxwmqcOkHNLj/U/uF\nGINEctqCZ57m8Z2pXx+ahUyBv3iZyk8Ksgi+fTBzMCAIG6elC8ztSmBxFakNa/Y9\n+6fLQ5lW1fDE5EKZt5J83cK3mOwSbZJrnZdM/wKFxXWoxVRnNNfWUaK5b90QQUWx\nAPZZgA7HtYPJoAQJKV2CCF/d04xebwwx0lVyxugMWR6OX9HBIx8fFj8CM5TJtixa\nBZVj2SasS4L2xr3m5xv9dJ1oDVOTR1sB6YKgoP/RY9JfAchfWVuTeCGuyrx5fSyw\n/LMwzbE/IGGAj+pu0o1pGEeKISQKYuSOpi6jhJc7UyYQiti6LM/E9yd3skqaab0C\n4IOno+0SQiBMJ/XTO0rXCA+KujcuXbX2lZEPJm4SszM=\n=hJA3\n-----END PGP MESSAGE-----"
val encryptedTextPGP = "-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v1.4.13 (Darwin)\n\nhQEMA0ERZBa1uzV3AQgAjYvs1C6gs0mHMu7Nr3jC+MGsV+PESDlRK54pNBJ3Wqvc\n+WCP1DS1OE2KeBkPNNX+Kz8ca/rK8Xo8LyofM3lcr/qzBSY5TKb7ap71U9Qy3uf0\nq6PsYGx/5ljkpAykrrmHz9jfeUMWGvP0kYsj52mFLjR7DTtzZuBc0SeTf9jgg5u5\nr6G3I265LcRCoOU1oVNiSNkgqeyXdbKSNaTA7GgmkH+VCnNs/4sRCMalh0Q4eTo6\nQrlAfplcy8tzwMnEqfAnJFvUEitKYJfOtvJ8a76N/Hh7kKrv6p/bGzH+mrWdrwQQ\njsBiwHCb7ogLIEtVWLjJNOTDxAXpznebsUZn7eAkUdJsAYrYjyMhGOcbzxXRTeVD\nSj6wNWsO7i5mcGqfPnx0zyl3ZihgESjacdFJuQUtKsdAY+EWef3MXxRZqXTg4kAl\nhSx9GP0T37/0LSbRcAu988BfdQqLLzhNMZEhQCST25nuBQXLx2q4FV5S0nuo\n=Q7bt\n-----END PGP MESSAGE-----"

....

val privateKeyPgpDataFormat = new PGPDataFormat
privateKeyPgpDataFormat.setKeyFileName(privateKeyFileName)
privateKeyPgpDataFormat.setKeyUserid(keyUserid)
privateKeyPgpDataFormat.setPassword(keyPass)

....

from("direct:input")
  .unmarshal(privateKeyPgpDataFormat)
  .to("mock:decrypted")

...

val exchange = new DefaultExchange(camelContext)
exchange.getIn.setBody(encryptedText)
camelContext.createProducerTemplate.send("direct:input", exchange)

....

我可以解密使用 BouncyCastle 加密的字符串,但是当我尝试使用 GnuPG 解密在 cmd 行上加密的字符串时出现错误:

  org.bouncycastle.openpgp.PGPException: exception decrypting session data

  ....

  Caused by: javax.crypto.BadPaddingException: unknown block type

我认为我的密钥不是问题,因为只要我不解密使用 GnuPG 加密的内容,我就可以使用该密钥进行加密和解密。

4

0 回答 0