Skip to main content

Basic object detection in python using OpenCv and Numpy - by Dustbiin

Read data from .pfx file for Digita Signature - by Dustbiin

Their is many way to read data for data for digital signature but hear we discus reading data from .pfx file - 

code for read .pfx file -


import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.Enumeration;

import javax.net.ssl.KeyManagerFactory;

public class PdfDemo
{
public static void checkExpire()
{
try
{
KeyManagerFactory kmf = javax.net.ssl.KeyManagerFactory.getInstance( "SunX509" );
KeyStore keystore = KeyStore.getInstance( "PKCS12" );
char[] password = "123456".toCharArray();
keystore.load( new FileInputStream( "demo.pfx" ), password );
//keystore.load(new FileInputStream(certificate), password);
kmf.init( keystore, password );
Enumeration<String> aliases = keystore.aliases();
while ( aliases.hasMoreElements() )
{
String alias = aliases.nextElement();
if ( keystore.getCertificate( alias ).getType().equals( "X.509" ) )
{
X509Certificate certificate = ( (X509Certificate) keystore.getCertificate( alias ) );
Date expDate = ( (X509Certificate) keystore.getCertificate( alias ) ).getNotAfter();
Date fromDate = ( (X509Certificate) keystore.getCertificate( alias ) ).getNotBefore();
String name = ( (X509Certificate) keystore.getCertificate( alias ) ).getSigAlgName();
System.out.println( "Certificate all data: " + certificate );
System.out.println( "Name : " + certificate.getPublicKey() );
System.out.println( "Exp Date:-" + expDate );
System.out.println( "From Date:-" + fromDate );
System.out.println( "Subject : " + certificate.getSubjectDN() );
System.out.println( "Issuer : " + certificate.getIssuerDN() );
}
}
}
catch ( Exception e )
{
e.printStackTrace();
}
}

public static void main( String[] args )
{
checkExpire();
System.out.println( "Reading done" );
}
}

output -


Certificate all data: [
[
Version: V3
Subject: C=IN, EMAILADDRESS=demo@example.com, OU=, O=demo, CN=Dustbiin
Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5

Key: Sun RSA public key, 2048 bits
params: null
modulus: 265336066019994661758135761240893812139530528426649324371138054602283392649996035554374356246911836557614185165157636366942403105417393685285867558881503724078931096303789527923521284936006367618591171876828718638940643898340213452948430602163830253219825666276523963883067358233974561533676717442254513372596858439759177998432202366508679458231639303521679586613639935174856502865572148970757069628337038242721966925616052217419475221098081263584162242572578426856829874012418601575873513742699948808390895451364219283740151610117524821110127238427450659985255544100865448404804004521849709911765542184013
public exponent: 65545
Validity: [From: Thu May 07 23:12:56 IST 2020,
To: Wed May 07 23:12:56 IST 2025]
Issuer: C=IN, EMAILADDRESS=demo@example.com, OU=, O=demo, CN=Dustbiin
SerialNumber: [ -1513ee55 233e240f 11f4]

Certificate Extensions: 2
[1]: ObjectId: 1.2.840.113583.1.1.10 Criticality=false
Extension unknown: DER encoded OCTET string =
0000: 04 02 05 00 ....


[2]: ObjectId: 2.5.29.15 Criticality=false
KeyUsage [
DigitalSignature
Data_Encipherment
Key_Agreement
]

]
Algorithm: [SHA1withRSA]
Signature:
0000: 49 D5 07 DE 09 83 75 7A AC 4D EB D1 F3 F9 4A 45 I.....uz.M....JE
0010: DB 7C 21 DE EF 90 3D 7B B3 1F 2E 08 9A F2 3F D3 ..!...=.......?.
0020: 5E 35 40 D9 B0 9A 8A BF BD 83 CE 66 64 3B EE 25 ^5@........fd;.%
0030: 5A 72 CF 39 61 42 68 F9 CD 5E 8A D8 3A 86 B1 2C Zr.9aBh..^..:..,
0040: 26 85 E6 F1 5C AD E1 37 9C DF 6D A1 FD 40 AD F9 &...\..7..m..@..
0050: 21 3F 8A B4 5A E3 06 38 8E DA C5 24 13 29 85 3C !?..Z..8...$.).<
0060: 80 ED A1 27 37 03 F9 AF F2 96 0B 67 9A 16 65 5A ...'7......g..eZ
0070: 5F B6 37 64 18 7F 97 A5 92 1D C7 B0 B0 49 10 60 _.7d.........I.`
0080: 82 01 52 2F 3A 41 0B C3 7B E1 02 5B 9C D6 24 4F ..R/:A.....[..$O
0090: 2C EC 49 2A 4E E9 4E 9D 89 58 65 14 8C 0E 14 D9 ,.I*N.N..Xe.....
00A0: B8 C8 C5 76 B8 AB 81 EE 01 04 D4 8A F2 2B 1F BF ...v.........+..
00B0: 3E A6 89 BE DA E6 79 BB 63 77 0A E7 56 EA 43 1E >.....y.cw..V.C.
00C0: DC FE D4 97 17 F2 13 40 CC 98 6B A0 2A D1 B8 F7 .......@..k.*...
00D0: FF 3B C5 4A FD C1 79 7C 54 69 1F 0F DE B5 91 D5 .;.J..y.Ti......
00E0: 11 DD 19 57 CF E4 EE CC BB 60 AE 19 FB D7 3A F1 ...W.....`....:.
00F0: 95 28 C6 3C E7 9A ED 93 39 7E 10 83 BE C5 36 FA .(.<....9.....6.

]
Name : Sun RSA public key, 2048 bits
params: null
modulus: 26533606601999466175813576124089381213953052842664351419564739324371138054602283392649996035554374356246911836557614185165157636366942403105417393685285867558881503724078931096303789527923521284936006367618591171876828718638940643898340213452948430602163830253219825666276523963883067358233974561533676717442254513372596858439759177998432202366508679458231639303521679586613639935174856502865572148970757069628337038242721966925616052217419475221098081263584162242572578426856829874012418601575873513742699948808390895451364219283740151610117524821110127238427450659985255544100865448404804004521849709911765542184013
public exponent: 65537
Expiray Date:-Wed May 07 23:12:56 IST 2025
From Date:-Thu May 07 23:12:56 IST 2020
Subject : C=IN, EMAILADDRESS=demo@example.com, OU=, O=demo, CN=Dustbiin
Issuer : C=IN, EMAILADDRESS=demo@example.com, OU=, O=demo, CN=Dustbiin
Reading done

Comments

Popular posts from this blog

Custom cell color in Excel Apache POI - By Dustbiin

Create custom color for cell background by using java color class Create custom color- XSSFWorkbook workBook = new XSSFWorkbook (); IndexedColorMap colorMap = workbook.getStylesSource().getIndexedColors(); Font tableHeadOneFontStyle = workbook.createFont();  tableHeadOneFontStyle.setBold( true ); tableHeadOneFontStyle.setColor( IndexedColors.BLACK.getIndex() ); XSSFCellStyle tableHeaderOneColOneStyle = workbook.createCellStyle(); tableHeaderOneColOneStyle.setFont( tableHeadOneFontStyle ); tableHeaderOneColOneStyle.setFillForegroundColor( new XSSFColor( new java.awt.Color( 255, 231, 153 ), colorMap ) ); tableHeaderOneColOneStyle.setFillPattern( FillPatternType.SOLID_FOREGROUND ); tableHeaderOneColOneStyle = setLeftRightBorderColor( tableHeaderOneColOneStyle ); tableHeaderOneColOneStyle = alignCenter( tableHeaderOneColOneStyle );

Create design by connecting dot's using opencv and numpy - by Dustbiin

Create basic design by using connecting dot's using your mouse- I have been create this by using mouse event check out the code below- use Python, OpenCv , NumPy import numpy as np import cv2 def click_event(event , x , y , flags , param): if event == cv2.EVENT_LBUTTONDOWN: print(x , " , " , y) font = cv2.FONT_HERSHEY_SIMPLEX strXY = str(x) + ' , ' + str(y) # cv2.putText(img,strXY, (x, y), font, .1, (255, 255, 0), 2) cv2.circle(img , (x , y) , 3 , ( 0 , 0 , 255 ) , - 1 ) points.append((x , y)) if len(points) >= 2 : cv2.circle(img , points[- 1 ] , 3 , ( 0 , 0 , 255 ) , - 1 ) # cv2.putText(img,strXY, points[-1], font, .1, (255, 255, 0), 2) cv2.line(img , points[- 2 ] , points[- 1 ] , ( 0 , 0 , 255 ) , 1 ) cv2.imshow( "Image" , img) points = [] img = np.zeros(( 512 , 512 , 3 )) cv2.imshow( "Image" , img) cv2.setMouseCallback( 'Image' ...