如何用Cryptix.jar这个加密包里边的DES算法、CBC模式对字符串加密?

maxy7809 2001-11-13 02:19:26
我需用用DES算法,CBC模式加密数据,可是总是不正确,加密后再解回来,结果就错了,请高人指点。
我是这样初始化的:
Cipher cryptor = Cipher.getInstance(Cipher.getInstance("DES", "Cryptix"),(Mode)Mode.getInstance("CBC", "Cryptix"),PaddingScheme.getInstance("PKCS#5"));
这个声明和Cryptix的doc里边有点区别,doc里边的第一个参数是:Cipher.getInstance("DES", "SUN"),这样执行的时候包错,说不存在SUN这个provider。

如果这样声明的话:Cipher cryptor = Cipher.getInstance("DES", "Cryptix");
结果是正确的,但是这样好像用的不是CBC模式,而是CFB模式。

怎样才能正确的时候CBC模式加密呢?
...全文
133 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
maxy7809 2001-11-13
  • 打赏
  • 举报
回复
已经加了,结果还是不正确。如果不是用CBC mode,结果就是正确的,为什么啊?
skyyoung 2001-11-13
  • 打赏
  • 举报
回复
有没有在JDK1.3\jre\lib\security\java.security文件里加。
#
# This is the "master security properties file".
#
# In this file, various security properties are set for use by
# java.security classes. This is where users can statically register
# Cryptography Package Providers ("providers" for short). The term
# "provider" refers to a package or set of packages that supply a
# concrete implementation of a subset of the cryptography aspects of
# the Java Security API. A provider may, for example, implement one or
# more digital signature algorithms or message digest algorithms.
#
# Each provider must implement a subclass of the Provider class.
# To register a provider in this master security properties file,
# specify the Provider subclass name and priority in the format
#
# security.provider.<n>=<className>
#
# This declares a provider, and specifies its preference
# order n. The preference order is the order in which providers are
# searched for requested algorithms (when no specific provider is
# requested). The order is 1-based; 1 is the most preferred, followed
# by 2, and so on.
#
# <className> must specify the subclass of the Provider class whose
# constructor sets the values of various properties that are required
# for the Java Security API to look up the algorithms or other
# facilities implemented by the provider.
#
# There must be at least one provider specification in java.security.
# There is a default provider that comes standard with the JDK. It
# is called the "SUN" provider, and its Provider subclass
# named Sun appears in the sun.security.provider package. Thus, the
# "SUN" provider is registered via the following:
#
# security.provider.1=sun.security.provider.Sun
#
# (The number 1 is used for the default provider.)
#
# Note: Statically registered Provider subclasses are instantiated
# when the system is initialized. Providers can be dynamically
# registered instead by calls to either the addProvider or
# insertProviderAt method in the Security class.

#
# List of providers and their preference orders (see above):
#
security.provider.1=sun.security.provider.Sun
security.provider.2=com.sun.rsajca.Provider

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧