感谢曹晓钢,非常感谢~!(1分)

  • 主题发起人 主题发起人 yuanzi
  • 开始时间 开始时间
Y

yuanzi

Unregistered / Unconfirmed
GUEST, unregistred user!
非常感谢你关于我那篇加密解密问题的回复,由于这几天看世界杯,所以很少上网。仔细
阅读了一下它的文档,问题应该是出在那个地方,加密解密我换了一种方式实现,但不是
很好,还是得改成用jce实现。最应该感谢你的地方,是你给我提供了一种很好解决问题的
方法,那就是多看文档,谢谢~!
 
不客气。[:)]
哎,我回复的帖子里好像有非法字符,导致那个帖子无法看了。我自己也收不到email通知,
你把非法字符都删掉,适当删节贴上来吧?
我自己还想留作参考呢 :)
 
是这个吗??
曹晓钢 在 2002-5-29 0:17:43 提供了如下回答, 请您查阅和评估:
--------------------------------------------------------------------------
---
对不起,我说过要帮你看一下的,一直忙,刚才给你试了一下。
你用的是JCE.在JCE文档之中,其实已经包含了使用JCE的步骤。
JCE使用的是可插入式的构造,就是说,JCE的具体实现是依靠provider来实现的。
JCE已经被
整合进入JDK 1.4的下载包了。而jdk 1.2和jdk 1.3还是需要你手工配置。
我们来看看文档中是怎么写的:

There are two types of JCE installations supported:
The JCE 1.2.1 framework is an "installed" extension. JCE providers are
installed or bundled.
The JCE 1.2.1 framework and JCE providers are located on the class path
(not installed extensions).
Thus, there are a couple possible ways of installing provider classes,
depending on how the JCE 1.2.1 framework is installed:
Install the JAR file containing the provider classes as an "installed" or
"bundled" (also known as "download") extension if the JCE 1.2.1 framework
is an installed extension.
Place the JAR file containing the provider classes anywhere on the
CLASSPATH if the JCE 1.2.1 framework is on the CLASSPATH.
Note: A provider JAR file will be considered an installed extension if it
is placed in the standard place for the JAR files of an installed
extension:
<java-home>/lib/ext [Win32]
<java-home>/lib/ext [Solaris]

Here <java-home> refers to the directory where the runtime software is
installed, which is the top-level directory of the JRE or the jre
directory in the JavaTM 2 SDK software. For example, if you have J2SDK v
1.2.2 installed on Solaris in a directory named jdk1.2.2, you need to
install the JAR file in the following directory:
jdk1.2.2/jre/lib/ext
Similarly, if you have JavaTM 2 Runtime Environment v 1.2.2 installed on
Solaris in a directory named jre1.2.2, you need to install the JAR file in
the following directory:
jre1.2.2/lib/ext
If a provider JAR file is placed anywhere other than the standard place
for installed extensions (e.g., in a directory on your class path
instead), it will be considered "bundled."
For more information on "installed" extensions, see Installed Extensions.

For more information on "bundled" extensions, see Bundled Extensions.
Configuring the Provider
The next step is to add the provider to your list of approved providers.
This isdo
ne statically by editing the security properties file
<java-home>/lib/security/java.security [Win32]
<java-home>/lib/security/java.security [Solaris]
Here <java-home> refers to the directory where the JRE was installed. For
example, if you have J2SDK v 1.2.2 installed on Solaris in a directory
named jdk1.2.2, you need to edit the following file:
jdk1.2.2/jre/lib/security/java.security
Similarly, if you have JavaTM 2 Runtime Environment, Standard Edition, v
1.2.2 installed on Solaris in a directory named jre1.2.2, you need to edit
this file:
jre1.2.2/lib/security/java.security
For each provider, this file should have a statement of the following
form:
security.provider.n=masterClassName
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.
masterClassName must specify the fully qualified name of the provider's
"master class". The provider vendor should supply you this name.
J2SE comes standard with a provider named "SUN", which is automatically
configured as a static provider in the java.security properties file, as
follows:
security.provider.1=sun.security.provider.Sun
(The "SUN" provider's master class is the Sun class in the
sun.security.provider package.)
Note that when you install JCE 1.2.1 (the jce1_2_1.jar extension), the
"SunJCE" provider that is also included with the JCE 1.2.1 release is not
automatically installed. That is, if you want to use the "SunJCE"
provider, you need to install the sunjce_provider.jar file as an optional
package (extension) and explicitly register the "SunJCE" provider - either
statically or dynamically, as described in this section.
In order to statically add "SunJCE" to your list of providers, you need to
edit the security properties file to contain a line of the format shown
above. For example, to make "SunJCE" the second preferred provider, add
the following line to the java.security file below the line for the "SUN"
provider:
security.provider.2=com.sun.crypto.provider.SunJCE
行了,看这么多就可以了。
按照他的说法,只需要把这两个包放到classpath中,并且修改java.security文件就
可以了。
Visual agae for Java的内置JRE的配置文件位于IBM Visual age for Java/ide/lib
里面,你可以找到java.security文件。
按照文档所写,我们加上如下一行:
security.provider.2=com.sun.crypto.provider.SunJCE
然后保存。
为了能让你的程序编译正确,我们把jce1_2_1.jar import到一个新的project JCE中
去,
而把你的第一段程序放到一个JCETest的工程里去。在window->Options里面找到
Resource ->
workbench class path,把jce1_2_1.jar和sunjce_provider.jar放倒classpath里
面。然后执行
En1.令人失望的是,错误依然。
无可怀疑,JCE一定是正确的,那什么错误了呢?注意到文档中特别提到:
Note: A provider JAR file will be considered an installed extension if it
is placed in the standard place for the JAR files of an installed
extension:
<java-home>/lib/ext [Win32]
<java-home>/lib/ext [Solaris]
你看,这两个JAR文件需要放到lib/ext目录下。而IBM的VAJ的ide/lib目录下并没有
ext目录。
下面的事情就好办了。按照文档所说,我们在VAJ的ide/lib下新建ext目录,然后把
JCE的下载包中的lib目录下的4个jar文件copy到这个ide/lib/ext目录,最后把这4个
文件
加入workbench classpath里面去。
由于所有的包都已经包含在workbench classpath中,在En1本身的classptah就不要
再包含JCE工程或者其他jar文件了。
好,这次再运行En1,哈!成功了。
这就是运行结果:
[B@13c3
This is just an example:abd
Encrypt the cleartext
z?Bb0`j???7_?A?f?~.?T?a&amp;??B??
[B@2624
[B@2a5e
Decrypt the ciphertext
This is just an example:abd
注意,我用的是英文的windows系统和英文VAJ,所以你看到的应该有所不同。
你所说在JDK1.4中运行正常,是因为JDK1.4已经内置JCE,所以你如果去看他的
java.security文件,应该已经包含了
security.provider.2=com.sun.crypto.provider.SunJCE
这一句。
总结一下,其实很多问题看起来很困难,但是在文档中已经全部提到了。如果yuanzi
同志能够
在遇到问题的时候仔仔细细看看文档,这个问题早就迎刃而解了。
--------------------------------------------------------------------------
---
该问题的URL是: http://www.delphibbs.com/delphibbs/dispq.asp?LID=1114886
欢迎经常光顾,争取上大富翁排行榜。
大富翁论坛(http://www.delphibbs.com/delphibbs)
 
后退
顶部