PSS parameter recovery and encoding : SHA1 Secure Hash Algorithm « Security « Java Tutorial






import java.security.AlgorithmParameters;
import java.security.Security;
import java.security.Signature;
import java.security.spec.PSSParameterSpec;

import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.util.ASN1Dump;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

    Signature signature = Signature.getInstance("SHA1withRSAandMGF1", "BC");
    signature.setParameter(PSSParameterSpec.DEFAULT);

    AlgorithmParameters params = signature.getParameters();

    ASN1InputStream aIn = new ASN1InputStream(params.getEncoded("ASN.1"));

    System.out.println(ASN1Dump.dumpAsString(aIn.readObject()));
  }
}








36.42.SHA1 Secure Hash Algorithm
36.42.1.Basic IO example using SHA1
36.42.2.PSS parameter recovery and encoding
36.42.3.Use SHA1
36.42.4.Encrypt a password