Calendario |
| l | m | m | g | v | s | d |
---|
30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|
|
Verificare la firma in Java
import java.io.*; import java.security.*; import java.security.cert.*; import java.security.spec.*; import org.apache.commons.io.IOUtils;
import sun.misc.BASE64Decoder;
class VerSig {
public static void main(String[] args) {
try { String signedText = "SOME/CHALLENGE/GENERATED/BY/YOUR/SIT"; String signature = "Ce3nAfKqekWzSbUaMcjQ1aFtRqZsvCUNs..........ucy81Pouq+NQplI5cZatJoyWYDmQ=="; String sigAlg = "SHA256withRSA"; String certificate ="MIIFwDCCA6igAwIBAgIII...........YBrEwsok/rEpmGViquYr9+dLP"; BASE64Decoder decoder = new BASE64Decoder(); byte[] signatureByte = decoder.decodeBuffer(signature); byte[] certificateByte =decoder.decodeBuffer(certificate); //X509Certificate certUser= X509Certificate.getInstance(certificateByte);
String certificatePath = "C:\\Users\\pippo\\Desktop\\test.cer"; // convert String into InputStream InputStream inStream = new ByteArrayInputStream(certificateByte); //InputStream inStream = new FileInputStream(certificatePath); CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate)cf.generateCertificate(inStream); inStream.close(); PublicKey pubKey = cert.getPublicKey(); System.out.print(pubKey.getAlgorithm()) ; Signature signatureVerifier = Signature.getInstance("SHA256withRSA");//SHA1withRSA signatureVerifier.initVerify(pubKey); System.out.println(signatureVerifier.verify(signatureByte)); } catch (Exception e) { System.err.println("Caught exception " + e.toString()); } } }
mercoledì, 05 giu 2013 Ore. 10.04
|
Archivio Posts |
Anno 2020
Anno 2018
Anno 2015
Anno 2013
Anno 2011
Anno 2010
Anno 2009
Anno 2008
|
Statistiche |
- Views Home Page: 14.502
- Views Posts: 57.378
- Views Gallerie: 2.837
- n° Posts: 117
- n° Commenti: 1
|
|