Finding the length of the public key

1k Views Asked by At

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
    }
}
1

There are 1 best solutions below

0
On

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()