⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 一个用java开发的会话密钥程序,可能对你有所帮助.mht

📁 JAVA核心源代码及算法,适合入门的初学者,可以让你快的入门
💻 MHT
📖 第 1 页 / 共 5 页
字号:
cipher=3DCipher.getInstance("PBEWithSHAAndTwofish-CBC");<BR>cipher.init(C=
ipher.ENCRYPT_MODE,key,paramSpec);<BR>//Encrypt=20
                              the byte[]<BR>byte[]=20
                              =
cipherPriKey=3Dcipher.doFinal(privateKeyBytes);<BR>//write=20
                              out salt ,and then the=20
                              cipherPriKey<BR>ByteArrayOutputStream =
baos=3Dnew=20
                              =
ByteArrayOutputStream();<BR>baos.write(salt);<BR>baos.write(cipherPriKey)=
;<BR>return=20
                              baos.toByteArray();<BR>}=20
                              =
<BR><BR><BR><BR>//=D3=C3=BB=E1=BB=B0=C3=DC=D4=BF=BC=D3=C3=DC=B8=F8=B6=A8=B5=
=C4=CE=C4=BC=FE=A3=AC=C8=BB=BA=F3=D3=C3=B9=AB=D4=BF=BC=D3=C3=DC=BB=E1=BB=B0=
=C3=DC=D4=BF=A3=AC=B2=A2=B4=E6=C8=EB=CE=C4=BC=FE=D6=D0<BR>//=D7=EE=BA=F3=BC=
=D3=C3=DC=BA=F3=B5=C4=CE=C4=BC=FE=D3=C9=C3=DC=D4=BF=B3=A4=B6=C8+=D2=D1=BC=
=D3=C3=DC=B5=C4=C3=DC=D4=BF=A3=A8=BB=E1=BB=B0=C3=DC=D4=BF=A3=A9+=C3=DC=CE=
=C4<BR>public=20
                              static void encrypt()throws=20
                              =
Exception{<BR><BR>//=D7=AA=BB=BB=B3=C9RSA=C3=DC=D4=BF<BR>X509EncodedKeySp=
ec=20
                              keySpec=3Dnew=20
                              =
X509EncodedKeySpec(publicKeyBytes);<BR>KeyFactory=20
                              =
keyFactory=3DKeyFactory.getInstance("RSA");<BR>PublicKey=20
                              =
publickey=3DkeyFactory.generatePublic(keySpec);<BR>//=B4=F2=BF=AA=B4=E6=D6=
=FC=C3=DC=CE=C4=B5=C4=CE=C4=BC=FE<BR>DataOutputStream=20
                              output=3Dnew DataOutputStream(new=20
                              =
FileOutputStream(ENCRPTOR_TEXT_FILE));<BR>//=B4=B4=BD=A8RSA=B5=C4CIpher<B=
R>Cipher=20
                              =
rsaCipher=3DCipher.getInstance("RSA/ECB/PKCS1Padding");<BR>rsaCipher.init=
(Cipher.ENCRYPT_MODE,publickey);<BR>//=B4=B4=BD=A8=BB=E1=BB=B0=C3=DC=D4=BF=
(Rijndael)<BR>KeyGenerator=20
                              =
rijndaelKeyGenerator=3DKeyGenerator.getInstance("Rijndael");<BR>rijndaelK=
eyGenerator.init(256);<BR>Key=20
                              =
rijndaelKey=3DrijndaelKeyGenerator.generateKey();<BR>//=B9=AB=D4=BF=BC=D3=
=C3=DC=BB=E1=BB=B0=C3=DC=D4=BF=20
                              <BR>byte[]=20
                              =
encodedKeyBytes=3DrsaCipher.doFinal(rijndaelKey.getEncoded());<BR>output.=
writeInt(encodedKeyBytes.length);<BR>output.write(encodedKeyBytes);<BR>//=
=B2=FA=C9=FAIV=CF=F2=C1=BF<BR>SecureRandom=20
                              random=3Dnew SecureRandom();<BR>byte[] =
iv=3Dnew=20
                              =
byte[16];<BR>random.nextBytes(iv);<BR>output.write(iv);<BR><BR>//=BC=D3=C3=
=DC=D5=FD=CE=C4<BR>IvParameterSpec=20
                              spec=3Dnew IvParameterSpec(iv);<BR>Cipher=20
                              =
symmetricCipher=3DCipher.getInstance("Rijndael/CBC/PKCS5Padding");<BR>sym=
metricCipher.init(Cipher.ENCRYPT_MODE,rijndaelKey,spec);<BR>CipherOutputS=
tream=20
                              cos=3Dnew=20
                              =
CipherOutputStream(output,symmetricCipher);<BR>FileInputStream=20
                              input=3Dnew =
FileInputStream(TEXT_FILE);<BR><BR>int=20
                              =
theByte=3D0;<BR>while((theByte=3Dinput.read())!=3D-1){<BR>cos.write(theBy=
te);<BR>}<BR>input.close();<BR>cos.close();<BR>return;<BR>}<BR><BR><BR><B=
R>//=B5=C3=B5=BD=CB=BD=D4=BF<BR>private=20
                              static byte[] passwordDecrypt(char[]=20
                              password,byte[] ciphertext)<BR>throws=20
                              Exception{<BR>byte[] salt=3Dnew=20
                              byte[8];<BR>ByteArrayInputStream =
bais=3Dnew=20
                              =
ByteArrayInputStream(ciphertext);<BR>bais.read(salt,0,8);<BR>byte[]=20
                              remainingCiphertext=3Dnew=20
                              =
byte[ciphertext.length-8];<BR>bais.read(remainingCiphertext,0,ciphertext.=
length-8);<BR>PBEKeySpec=20
                              keySpec=3Dnew=20
                              PBEKeySpec(password);<BR>SecretKeyFactory=20
                              =
keyFactory=3DSecretKeyFactory.getInstance("PBEWithSHAAndTwofish-CBC");<BR=
>SecretKey=20
                              =
key=3DkeyFactory.generateSecret(keySpec);<BR>PBEParameterSpec=20
                              paramSpec=3Dnew=20
                              =
PBEParameterSpec(salt,ITERATIONS);<BR>Cipher=20
                              =
cipher=3DCipher.getInstance("PBEWithSHAAndTwofish-CBC");<BR>cipher.init(C=
ipher.DECRYPT_MODE,key,paramSpec);<BR>return=20
                              =
cipher.doFinal(remainingCiphertext);<BR>}<BR><BR><BR>//=BD=E2=C3=DC=BC=D3=
=C3=DC=B5=C4=CE=C4=BC=FE=20
                              <BR>public static void decrypt()<BR>throws =

                              Exception{<BR>FileInputStream fis=3Dnew=20
                              =
FileInputStream(ENCRYPT_PRIVATEKEY_FILE);<BR>ByteArrayOutputStream=20
                              baos=3Dnew ByteArrayOutputStream();<BR>int =

                              =
theByte=3D0;<BR>while((theByte=3Dfis.read())!=3D-1){<BR>baos.write(theByt=
e);<BR>}<BR>fis.close();<BR>//=B5=C3=B5=BD=B1=BB=BC=D3=C3=DC=B5=C4=CB=BD=D4=
=BF<BR>byte[]=20
                              =
keyBytes=3Dbaos.toByteArray();<BR>baos.close();<BR>//=B5=C3=B5=BD=CB=BD=D4=
=BF<BR>byte[]=20
                              =
sKey=3DpasswordDecrypt(password.toCharArray(),keyBytes);<BR>//=B2=FA=C9=FA=
RSA=CB=BD=D4=BF<BR>PKCS8EncodedKeySpec=20
                              keySpec=3Dnew=20
                              PKCS8EncodedKeySpec(sKey);<BR>KeyFactory=20
                              =
keyFactory=3DKeyFactory.getInstance("RSA");<BR>PrivateKey=20
                              =
privateKey=3DkeyFactory.generatePrivate(keySpec);<BR>Cipher=20
                              =
rsaCipher=3DCipher.getInstance("RSA/ECB/PKCS1Padding");<BR><BR>DataInputS=
tream=20
                              dis=3Dnew DataInputStream(new=20
                              =
FileInputStream(ENCRPTOR_TEXT_FILE));<BR>//=B6=C1=C3=DC=CE=C4=D6=D0=C3=DC=
=C2=EB=B3=A4=B6=C8=BA=CD=C3=DC=C2=EB=20
                              <BR>byte[] encryptedKeyBytes=3Dnew=20
                              =
byte[dis.readInt()];<BR>dis.readFully(encryptedKeyBytes);<BR>rsaCipher.in=
it(Cipher.DECRYPT_MODE,privateKey);<BR>byte[]=20
                              =
rijdaelKeyBytes=3DrsaCipher.doFinal(encryptedKeyBytes);<BR>//=B5=C3=B5=BD=
=BB=E1=BB=B0=C3=DC=D4=BF<BR>SecretKey=20
                              rijndaelKey=3Dnew=20
                              =
SecretKeySpec(rijdaelKeyBytes,"Rijndael");<BR>byte[]=20
                              iv=3Dnew=20
                              =
byte[16];<BR>dis.read(iv);<BR>IvParameterSpec=20
                              spec=3Dnew=20
                              =
IvParameterSpec(iv);<BR>//=D3=C3=BB=E1=BB=B0=C3=DC=D4=BF=BD=E2=C3=DC=D5=FD=
=CE=C4<BR>Cipher=20
                              =
cipher=3DCipher.getInstance("Rijndael/CBC/PKCS5Padding");<BR>cipher.init(=
Cipher.DECRYPT_MODE,rijndaelKey,spec);<BR><BR>CipherInputStream=20
                              cis=3Dnew=20
                              =
CipherInputStream(dis,cipher);<BR>FileOutputStream=20
                              fos=3Dnew=20
                              =
FileOutputStream(DENCRYPTOR_TEXT_FILE);<BR><BR>theByte=3D0;<BR>while((the=
Byte=3Dcis.read())!=3D-1){<BR>fos.write(theByte);<BR>}<BR>cis.close();<BR=
>fos.close();<BR>return;<BR>}<BR>public=20
                              static void main(String[] args)throws=20
                              =
Exception{<BR>createKey();<BR>encrypt();<BR>decrypt();<BR>}<BR>}<BR><BR><=
BR><BR><BR><BR><BR><BR><BR></TD>
                            <TD vAlign=3Dtop width=3D"14%">
                              <DIV align=3Dright><FONT=20
                              =
color=3Dgray>&nbsp;&nbsp;&nbsp;&nbsp;</FONT></DIV>
                              <SCRIPT type=3Dtext/javascript><!--
google_ad_client =3D "pub-1552958637257019";
google_ad_width =3D 160;
google_ad_height =3D 600;
google_ad_format =3D "160x600_as";
google_ad_channel =3D"";
google_ad_type =3D "text";
google_color_border =3D "A8DDA0";
google_color_bg =3D "EBFFED";
google_color_link =3D "0000CC";
google_color_url =3D "008000";
google_color_text =3D "6F6F6F";
//--></SCRIPT>

                              <SCRIPT=20
                              =
src=3D"http://pagead2.googlesyndication.com/pagead/show_ads.js"=20
                              type=3Dtext/javascript>
</SCRIPT>
                            </TD></TR></TBODY></TABLE>
                        <P></P></TD>
                      <TD vAlign=3Dtop width=3D"1%">&nbsp; </TD></TR>
                    <TR>
                      <TD width=3D"99%"></TD>
                      <TD =
width=3D"1%">&nbsp;</TD></TR></TBODY></TABLE></TD>
              <TR>
                <TD vAlign=3Dcenter =
height=3D73></TD></TR></TBODY></TABLE></TD>
        <TR>
          <TD vAlign=3Dtop height=3D73>
            <TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"98%" =
align=3Dcenter=20
border=3D0>
              <TBODY>
              <TR>
                <TD width=3D"1%" height=3D31>&nbsp;</TD>
                <TD width=3D"99%" height=3D31>
                  <P align=3Dleft><FONT color=3Dred><IMG=20
                  =
src=3D"http://www.cn-java.com/images/smalllogo.gif">=D5=FB=C0=ED=B7=A2=B2=
=BC</FONT></P>
                  <P align=3Dright>&nbsp;</P>
                  <P align=3Dleft>&nbsp;</P>
                  <TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%" =
border=3D0>
                    <TBODY>
                    <TR>
                      <TD bgColor=3D#dcdce7>
                        <TABLE cellSpacing=3D0 cellPadding=3D0 =
width=3D"96%"=20
                        align=3Dcenter border=3D0>
                          <TBODY>
                          <TR>
                            <TD>&nbsp;<FONT=20
                              =
color=3Dred>=B7=A2=D1=D4=C8=CB:</FONT><B>=B9=FD=BF=CD</B>&nbsp;&nbsp;&nbs=
p;=C8=D5=C6=DA=A3=BA2003-07-30
                              <HR>
                              Please can I find a full code to extract =
te=20
                              private key from a pem =
file<BR><BR><BR>&nbsp;<FONT=20
                              =
color=3Dred>=B7=A2=D1=D4=C8=CB:</FONT><B>dabenmao</B>&nbsp;&nbsp;&nbsp;=C8=
=D5=C6=DA=A3=BA2003-11-13
                              <HR>
                              =CE=D2=BD=AB=CE=C4=BC=FE=B8=C4=C3=FB=CE=AA =
yaoshi.java =
=D4=CB=D0=D0=B3=F6=C8=E7=CF=C2=B4=ED=CE=F3<BR>yaoshi.java:32:=20
                              class FileEncryptorRSA is public, should =
be=20
                              declared in a file named=20
                              FileEncryptorRSA.java<BR>public class=20
                              FileEncryptorRSA {<BR>^<BR>1=20
                              =
error<BR>=C7=EB=D6=B4=BD=CC<BR><BR><BR>&nbsp;<FONT=20

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -