亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1422 | 回復(fù): 0
打印 上一主題 下一主題

C Crypt Interoperate with Java Crypt [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2005-10-22 11:34 |只看該作者 |倒序瀏覽

There are many open source today.  this also works for the crypt projects.
Yet the  different crypt implementation have some compatibility issue between them.
1. Different implementations
C Crypt implementation
http://www.libtomcrypt.org/
Sun Crypt implematation:
http://java.sun.com
Bouncy Castle Crypt implematation:
http://www.bouncycastle.org/

2. Compatibilty issue.
[color="#800080"]libtomcrypt generate DSA key format can not be supported by java DSA implemation.
[color="#800080"]while bouncycastle do.
[color="#800080"]3. Implementation code.
import java.math.*;
import org.bouncycastle.crypto.params.*;
import org.bouncycastle.crypto.signers.DSASigner;
import org.bouncycastle.crypto.digests.SHA1Digest;
public class SignatureVerifier
{
   private DSASigner dsaSigner = null;

   /** Build Public Key object from the y/p/q/g data files */
   public SignatureVerifier()
      throws FileNotFoundException, IOException
   {
      // Load key parameters from data files
      BigInteger y = readBigInt("y.dat");
      BigInteger p = readBigInt("p.dat");
      BigInteger q = readBigInt("q.dat");
      BigInteger g = readBigInt("g.dat");
     System.out.println( "Y: " + y + "
P: " + p + "
Q: " + q + "
G: " + g);
      DSAParameters dsaParams = new DSAParameters( p, q, g);
      DSAPublicKeyParameters dsaPubParams = new DSAPublicKeyParameters( y, dsaParams );
      dsaSigner = new DSASigner();
      dsaSigner.init( false, dsaPubParams );
   }
   /** Verify the header data
       headerData should be
   */
   public boolean verify( byte[] headerData, byte[] signature )
   {
      boolean valid = false;
      // Build SHA1 digest from the passed in header data
      SHA1Digest sha1 = new SHA1Digest();
      sha1.update( headerData, 0, headerData.length );
            
      byte[] sha1hash = new byte[ sha1.getDigestSize() ];
      sha1.doFinal( sha1hash, 0 );
      // Decompose signature into the r and s values
      byte[] rBytes = new byte[20];
      byte[] sBytes = new byte[20];
      System.arraycopy( signature, 0, rBytes, 0, 20);
      System.arraycopy( signature, 20, sBytes, 0, 20);
      BigInteger r = new BigInteger( 1, rBytes );
      BigInteger s = new BigInteger( 1, sBytes );
      valid = dsaSigner.verifySignature( sha1hash, r, s );
      return(valid);
   }
   /** Reads a BigInteger from a binary file */
   static public BigInteger readBigInt( String filename )  
          throws FileNotFoundException, IOException
   {
       FileInputStream intFIS = new FileInputStream( filename );
       int numBytes = intFIS.available();
       byte[] fileBytes = new byte[numBytes];
       intFIS.read( fileBytes );
       intFIS.close();
       BigInteger bigInt = new BigInteger( 1, fileBytes );
       return(bigInt);
   }
   public static void main( String args[])
   throws Exception
   {
       SignatureVerifier sigVerify = new SignatureVerifier();
    try{
            // Read signature from test file
            byte[] signature =  new byte[40];
            FileInputStream fis = new FileInputStream( "test.txt.sig" );
            fis.read(signature );
            fis.close();
            // Read content file (simulated header)
            byte[] header = new byte[140];
            fis = new FileInputStream( "test.txt" );
            fis.read( header );
            fis.close();
         
                       boolean sigOkay = sigVerify.verify( header, signature );
            System.out.println("signatureOkay=" + sigOkay );
           }catch(Exception e){
               e.printStackTrace();
        }
   }
}


本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/9924/showart_52953.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP