0

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
    }
}
user207421
  • 305,947
  • 44
  • 307
  • 483
Student
  • 55
  • 2
  • 13

1 Answers1

3

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()
Chris Martin
  • 30,334
  • 10
  • 78
  • 137