Student
Student

Reputation: 55

Finding the length of the public key

I'm trying to find the length of a DSA public key but it can't find the method .length, I've made sure I have the right imports but it doesn't seem to work. The snippet is below, is there a special function to find this?

 //my imports 
  import java.util.*;       
  import java.io.*;                         
  import javax.crypto.*;                        
  import javax.crypto.spec.*;
  import java.security.*;

public boolean SelObj(int k, PublicKey c) throws java.rmi.RemoteException{
    for(int j =1; j<c.bitLength(); ++j) {
        //some code
    }
}

Upvotes: 0

Views: 1066

Answers (1)

Chris Martin
Chris Martin

Reputation: 30736

The bit length of the byte array encoding:

c.getEncoded().length * Byte.SIZE

The bit length of the integer value:

import java.security.interfaces.DSAPublicKey

((DSAPublicKey) c).getY().bitLength()

Upvotes: 3

Related Questions