我能否在多个方法中使用相同的 Cipher
对象,因为 getInstance
和 init
的方法参数不会改变?
例如,假设应用程序的多个部分使用实用程序类中的 decrypt
方法。所有传递的加密值都是使用相同的 key 和算法生成的。那么,我可以重复使用相同的 Cipher
对象吗?
Cipher
的多次创建真的值得担心吗(这可能会导致创建KeySpec
、SecretKey
对象)?
最佳答案
是的。
如文档所述:
Upon finishing, this method resets this cipher object to the state it was in when previously initialized via a call to init. That is, the object is reset and available to encrypt or decrypt (depending on the operation mode that was specified in the call to init) more data.
关于java - Cipher 对象是否可重用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4816319/