请问java产生rsa密钥对,使用的是csp?还是pkcs?为什么和微软的公私钥长度不一样呢?

解决方案 »

  1.   


    package   com.XXX.common.security;   
        
      /**   
        *   <p>Title:   </p>   
        *   <p>Description:   </p>   
        *   <p>Copyright:   Copyright   (c)   2003</p>   
        *   <p>Company:   secrurity</p>   
        *   @author   Jim   Miao   
        *   @version   1.0   
        */   
        
      import   java.security.*;   
      import   java.security.interfaces.*;   
      import   javax.crypto.*;   
      import   java.io.*;   
        
      import   javax.crypto.Cipher;   
      import   javax.crypto.BadPaddingException;   
      import   javax.crypto.IllegalBlockSizeException;   
      import   javax.crypto.KeyGenerator;   
      import   java.security.Key;   
      import   java.security.InvalidKeyException;   
        
        
      public   class   RSAEnAndDecrypt   {   
              public   RSAEnAndDecrypt()   {   
              }   
              private   static   String   algorithm   =   "RSA";   
              private   static   Key   key   =   null;   
              private   static   Cipher   cipher   =   null;   
        
              private   static   void   setUp()   throws   Exception   {   
                      key   =   KeyGenerator.getInstance(algorithm).generateKey();   
                      cipher   =   Cipher.getInstance(algorithm);   
              }   
              private   static   byte[]   encrypt(String   input)   
                      throws   InvalidKeyException,   
                                    BadPaddingException,   
                                    IllegalBlockSizeException   {   
                      cipher.init(Cipher.ENCRYPT_MODE,   key);   
                      byte[]   inputBytes   =   input.getBytes();   
                      return   cipher.doFinal(inputBytes);   
              }   
        
              private   static   String   decrypt(byte[]   encryptionBytes)   
                      throws   InvalidKeyException,   
                                    BadPaddingException,   
                                    IllegalBlockSizeException   {   
                      cipher.init(Cipher.DECRYPT_MODE,   key);   
                      byte[]   recoveredBytes   =   
                          cipher.doFinal(encryptionBytes);   
                      String   recovered   =   
                          new   String(recoveredBytes);   
                      return   recovered;   
                  }   
      }   我只有实现的代码,要看具体的细节,只能读代码了