I found a difference in the output to PEM file that openssl generates with different versions.
I use following command to generate the PEM file
So for the same p12 file we get following output:
From version 0.9.8
Bag Attributes
friendlyName: alias
localKeyID: 54 69 6D 65 20 31 34 34 30 31 35 39 36 39 39 34 30 38
Key Attributes: <No Attributes>
-----BEGIN DSA PRIVATE KEY-----
MIIBuwIBAAKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADDHj+AtlEmaUVdQCJR
+1k9jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7qdf+t8Yb
+DtX58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgBxwIVAJdg
UI8VIwvMspK5gqLrhAvwWBz1AoGBAPfhoIXWmz3ey7yrXDa4V7l5lK+7+jrqgvlX
TAs9B4JnUVlXjrrUWU/mcQcQgYC0SRZxI+hMKBYTt88JMozIpuE8FnqLVHyNKOCj
rh4rs6Z1kW6jfwv6ITVi8ftiegEkO8yk8b6oUZCJqIPf4VrlnwaSi2ZegHtVJWQB
TDv+z0kqAoGAfq00gXUAZKs/5070DyJJ2OPmgTsMkRXeAclk3mlvejzaiswmM50i
NuV4EYP0SeSzxxzMNR+0U8xg8M/R7a4qMAsDiHixM8i/HGrqC5m+/Zabg3FVNVEQ
C1sFNiqeP3P6n986HrRK5WbEFcJKMZFAbFTwXeo0D6Uevi2ZzYrm0cgCFE6W9Uw2
ZHF1HYhy0L49DUQN79LL
-----END DSA PRIVATE KEY-----
Bag Attributes
friendlyName: alias
localKeyID: 54 69 6D 65 20 31 34 34 30 31 35 39 36 39 39 34 30 38
subject=/CN=HCP
issuer=/CN=HCP
-----BEGIN CERTIFICATE-----
MIICeDCCAjagAwIBAgIEHpWeZDALBgcqhkjOOAQDBQAwDjEMMAoGA1UEAxMDSENQ
MB4XDTE1MDgyMTEyMjEwOFoXDTE1MTExOTEyMjEwOFowDjEMMAoGA1UEAxMDSENQ
MIIBtzCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9E
AMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdrmVClpJ+f
6AR7ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXzrith1yrv
8iIDGZ3RSAHHAhUAl2BQjxUjC8yykrmCouuEC/BYHPUCgYEA9+GghdabPd7LvKtc
NrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3zwky
jMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/h
WuWfBpKLZl6Ae1UlZAFMO/7PSSoDgYQAAoGAfq00gXUAZKs/5070DyJJ2OPmgTsM
kRXeAclk3mlvejzaiswmM50iNuV4EYP0SeSzxxzMNR+0U8xg8M/R7a4qMAsDiHix
M8i/HGrqC5m+/Zabg3FVNVEQC1sFNiqeP3P6n986HrRK5WbEFcJKMZFAbFTwXeo0
D6Uevi2ZzYrm0cijITAfMB0GA1UdDgQWBBTo5c7HXDNXFjVl5cPJLHTKGqXXFTAL
BgcqhkjOOAQDBQADLwAwLAIUCI0RfR7sVsNpzMKFlCvx8G5nSZACFCkcmf5mPKoz
ytbeIPWod7vQNmEz
-----END CERTIFICATE-----
from version 1.0.1g the output is following:
Bag Attributes
friendlyName: alias
localKeyID: 54 69 6D 65 20 31 34 34 30 31 35 39 36 39 39 34 30 38
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
MIIBSwIBADCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdS
PO9EAMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdrmVCl
pJ+f6AR7ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXzrith
1yrv8iIDGZ3RSAHHAhUAl2BQjxUjC8yykrmCouuEC/BYHPUCgYEA9+GghdabPd7L
vKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3
zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImo
g9/hWuWfBpKLZl6Ae1UlZAFMO/7PSSoEFgIUTpb1TDZkcXUdiHLQvj0NRA3v0ss=
-----END PRIVATE KEY-----
Bag Attributes
friendlyName: alias
localKeyID: 54 69 6D 65 20 31 34 34 30 31 35 39 36 39 39 34 30 38
subject=/CN=HCP
issuer=/CN=HCP
-----BEGIN CERTIFICATE-----
MIICeDCCAjagAwIBAgIEHpWeZDALBgcqhkjOOAQDBQAwDjEMMAoGA1UEAxMDSENQ
MB4XDTE1MDgyMTEyMjEwOFoXDTE1MTExOTEyMjEwOFowDjEMMAoGA1UEAxMDSENQ
MIIBtzCCASwGByqGSM44BAEwggEfAoGBAP1/U4EddRIpUt9KnC7s5Of2EbdSPO9E
AMMeP4C2USZpRV1AIlH7WT2NWPq/xfW6MPbLm1Vs14E7gB00b/JmYLdrmVClpJ+f
6AR7ECLCT7up1/63xhv4O1fnxqimFQ8E+4P208UewwI1VBNaFpEy9nXzrith1yrv
8iIDGZ3RSAHHAhUAl2BQjxUjC8yykrmCouuEC/BYHPUCgYEA9+GghdabPd7LvKtc
NrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3zwky
jMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/h
WuWfBpKLZl6Ae1UlZAFMO/7PSSoDgYQAAoGAfq00gXUAZKs/5070DyJJ2OPmgTsM
kRXeAclk3mlvejzaiswmM50iNuV4EYP0SeSzxxzMNR+0U8xg8M/R7a4qMAsDiHix
M8i/HGrqC5m+/Zabg3FVNVEQC1sFNiqeP3P6n986HrRK5WbEFcJKMZFAbFTwXeo0
D6Uevi2ZzYrm0cijITAfMB0GA1UdDgQWBBTo5c7HXDNXFjVl5cPJLHTKGqXXFTAL
BgcqhkjOOAQDBQADLwAwLAIUCI0RfR7sVsNpzMKFlCvx8G5nSZACFCkcmf5mPKoz
ytbeIPWod7vQNmEz
-----END CERTIFICATE-----
So there is a difference in the private key.
Problem is that later we try to parse the private key from Java with following code:
KeyFactory keyFactory = KeyFactory.getInstance("DSA");
KeySpec privateKeySpec = new PKCS8EncodedKeySpec(Base64.decode(key));
keyFactory.generatePrivate(privateKeySpec);
then the output of version 0.9.8 is not parsed and fails with InvalidKeySpec.
Was something changed in OpenSSL and how can we avoid this?
Related
Studying the sip protocol, I got to the topic of the H264 codec. I began to receive data in the form of rtp packets. I managed to successfully get the following data from the package: Payload type (in my case 97), Timestamp, Sequence number and payload data (byte array). Next, I want to draw images encoded in this data. On the android platform, I use the android.media.MediaCodec class. I follow examples like MediaCodec failing on S7.
I create an instance of MediaCodec. Configuring with MediaFormat. Then I transfer the received bytes to inputBuffer and wait for updates via dequeueOutputBuffer. In my case, the dequeueOutputBuffer method always returns MediaCodec.INFO_TRY_AGAIN_LATER.
I was trying to process bytes before passing to MediaCodec. Defined nal_unit_type. I get 7, 8 and 28. I also defined startBit and endBit in the package. I tried to glue all packages starting with startBit and ending with endBit and transfer them to MediaCodec in a glued form. The result is the same - the dequeueOutputBuffer method always returns MediaCodec.INFO_TRY_AGAIN_LATER
Tell me what I missed.
The server sends the following information about the video to the SDP:
m=video 23542 RTP/AVP 97
b=TIAS:4096000
a=content:main
a=rtpmap:97 H264/90000
a=fmtp:97 profile-level-id=428028; max-fs=8192; packetization-mode=0; max-br=4096; max-fps=3000
a=sendrecv
Edit #1
For example, first received packet payload (array of unsigned byte):
27 42 00 28 95 a0 1e 00 89 f9 70 11 00 00 03 00
42 00 28 95 a0 1e 00 89 f9 70 11 00 00 03 00 01
00 28 95 a0 1e 00 89 f9 70 11 00 00 03 00 01 00
I would venture to suggest that this is a Single NAL Unit Packet. This packet has no padding.
By rfc3984/1.3 i got in first byte:
// 0 1 2 3 4 5 6 7
// +-----+---------+
// | type |
// +-----+---------+
val nal_unit_type = payload[0].toInt() and 0b0_0_0_1_1_1_1_1
nal_unit_type == 7 And I decided that this package contains Sequence Parameter Set data. Next, I want to get the decrypt SPS and get useful information from it (width and height, frame rate ...)
I got in second byte:
// 0 1 2 3 4 5 6 7
// +-+-+-----------+
// |s|e|
// +-+-+-----------+
val start_bit = payload[1].toInt() and 0b1_0_0_0_0_0_0_0 != 0
// +-+-+-----------+
val end_bit = payload[1].toInt() and 0b0_1_0_0_0_0_0_0 != 0
start_bit == false and end_bit == true
Starting from the third byte (payload[2]), I parse the SPS.
Edit #2
I was wrong when I decided that the second byte for nal_unit_type 7 or 8 is the FU header (with start and end bits). The second byte of the payload is already the first byte of the SPS. Thus, I managed to successfully decrypt the SPS and, for example, find out that the image size 1920/1080 is encrypted there (as was expected). But this has not yet helped me in any way to draw the resulting video stream to the android surface view.
I have the following base 64 encoded string:
e4EdYQYDTpC7sN0K87elHA==
In Window.Atob in javascript it provides me with {aN»°Ý ó·¥ however when running the below code in Java it gives me
{�aN����
�
String encodedString = "e4EdYQYDTpC7sN0K87elHA==";
Decoder decoder = Base64.getDecoder();
byte[] decodedByte = decoder.decode(encodedString);
String decodedString = new String(decodedByte);
System.out.println(decodedString);
As you can see the output is extended ascii but I cannot seem to replicate the results of Window.atob in java.
The Byte output from Java is:
123
-127
29
97
6
3
78
-112
-69
-80
-35
10
-13
-73
-91
28
While the output should be:
123 194 129 029 097 006 003 078 194 144 194 187 194 176 195 157 032 195 179 194 183 194 165 028
Any ideas on what needs to be done in order to replicate the result.
I try to get phone numbers from string in german format. But I don't get it to full run. The input text is a full HTML-Page with lots of content, not only the numbers.
Possible Formats:
(06442) 3933023
(02852) 5996-0
(042) 1818 87 9919
06442 / 3893023
06442 / 38 93 02 3
06442/3839023
042/ 88 17 890 0
+49 221 549144 – 79
+49 221 - 542194 79
+49 (221) - 542944 79
0 52 22 - 9 50 93 10
+49(0)121-79536 - 77
+49(0)2221-39938-113
+49 (0) 1739 906-44
+49 (173) 1799 806-44
0173173990644
0214154914479
02141 54 91 44 79
01517953677
+491517953677
015777953677
02162 - 54 91 44 79
(02162) 54 91 44 79
I have tried:
$regex = '~(?:\+?49|0)(?:\s*\d{3}){2}\s*\d{4,10}~';
if(preg_match_all($regex, $input_imprint , $matches)){
print_r($matches);
}
But it doesn't match only a few formats. I have no idea to do it.
Here is a regex to match all your formats.
I would suggest then to replace all unwanted characters and you got your desired result.
(\(?([\d \-\)\–\+\/\(]+)\)?([ .\-–\/]?)([\d]+))
If you need a minimum length to match your numbers, use this:
(\(?([\d \-\)\–\+\/\(]+){6,}\)?([ .\-–\/]?)([\d]+))
https://regex101.com/r/CAVex8/143
updated, thanks for the suggestion #Willi Mentzel
[0-9]*\/*(\+49)*[ ]*(\([0-9]+\))*([ ]*(-|–)*[ ]*[0-9]+)*
Check this link: https://regex101.com/r/CAVex8/1
May introduce some false positives.
This one solved my problem (extracting phone numers from emails):
r"\+?[0-9]+([0-9]|\/|\(|\)|\-| ){10,}"
A plus sign optional at the front, followed by at least 1 number, followed by at least 10 numbers or delimiting characters such as /, (, ) or - or a space.
(There is no official "smallest number of digits" for a telephone number, but I assume they are all at least 11 digits long)
I'm adding this because #Kakul 's solution matched any lien of my text, and using #despecial 's my code would not terminate. (I am guessing it is too computationally expensive for my pc)
This is no solution for the asked question, just an advice for matching phonenumbers!
If you are about to store telephone numbers for you first time, then limit the amount of different accepted formats. Get rid of these for example:
(06442) 3933023
042/ 88 17 890 0
+49(0)121-79536 - 77
02162 - 54 91 44 79
Why?
You need to test more possible ways of inputting an invalid value.
Those formats you absolutely need to concider according to DIN 5008:
0873 376461
03748 37682358
05444 347687-350
0764 812632-41
0180 2 12334
0800 5 23234213
+49 30 3432622-113
0179 1111111
Here is what I came up with: Regex
^(([+]{1}[1-9]{1}[0-9]{0,2}[ ]{1}([1-9]{1}[0-9]{1,4}){1}[ ]{1}([1-9]{1}[0-9]{2,6}){1}([ -][0-9]{1,5})?)|([0]{1}[1-9]{1}[0-9]{1,4}[ ]{1}[0-9]{1,8}([ -][0-9]{1,8})?)?)
Positives:
06429 1111
06901 306180
06429 231
0800 3301000
0179 1111111
0873 376461
03748 37682358
05444 347687-350
0764 812632-41
0180 2 12334
0800 5 23234213
+49 6429 1111
+49 39857 2530
+55 11 2666-0054
+300 11 2666-0054
+49 641 20106 0
+49 641 20106
+49 30 3432622-113
Negatives:
++49 157 184977
+300 11 0000-0000
(06442) 3933023
(02852) 5996-0
(042) 1818 87 9919
06442 / 3893023
06442 / 38 93 02 3
06442/3839023
042/ 88 17 890 0
+49 221 - 542194 79
+49 (221) - 542944 79
0 52 22 - 9 50 93 10
+49(0)121-79536 - 77
+49(0)2221-39938-113
+49 (0) 1739 906-44
+49 (173) 1799 806-44
0173173990644
0214154914479
01517953677
+491517953677
015777953677
02162 - 54 91 44 79
(02162) 54 91 44 79
saddsadasdasd
asdasd
asdasd asdasd asd
asdasd
kjn asohas asdoiasd
23434 234 234 23
323
23434 234----234
///// ----
// id8834 3493934 //
Hey i have a little enhancement for despecial‘s Regex:
(\(?([\d \-\)\–\+\(]+\/?){6,}\)?([ .\-–\/]?)([\d]+))
It filters numbers that have too high occurrencies of /
I'm trying to decode a H264 raw protocol from a camera but I'm having some problems using the Jcodec H264Decoder. I receive an array of integers with the information from the camera. Below a sample of the data:
array: 00 00 01 FD 00 00 14 69 00 00 00 01 61 E4 80 6F D3 5B 76 97 DF 04 3A EF 54 97 0E D9 F5...more
The code I'm using is :
ByteBuffer bb = ByteBuffer.wrap( Utils.intArrayToByteArray(array, arraySize) );
bb.rewind();
// Create a buffer to hold the output picture which is big enough
Picture outBuffer = Picture.create( 1920, 1088, ColorSpace.YUV420 );
Picture pic = _decoder.decodeFrame( bb, outBuffer.getData() );
BufferedImage bufferedImage = JCodecUtil.toBufferedImage( pic );
When I try to run it, I get NullPointerException as follow:
Exception in thread "Thread-6" java.lang.NullPointerException
at org.jcodec.codecs.h264.H264Decoder$FrameDecoder.decodeFrame(H264Decoder.java:82)
at org.jcodec.codecs.h264.H264Decoder.decodeFrame(H264Decoder.java:61)
at br.com.grupogiga.security.xm.player.jcodec.JCodecPlayer.test_readNals(JCodecPlayer.java:122)
at br.com.grupogiga.security.xm.player.jcodec.JCodecPlayer.processNAL(JCodecPlayer.java:69)
at br.com.grupogiga.security.xm.player.XMH264Player$1$2.NALArrived(XMH264Player.java:143)
at br.com.grupogiga.security.xm.protocols.ProtocolParser.emitNALArrived(ProtocolParser.java:408)
at br.com.grupogiga.security.xm.protocols.ProtocolParser.run(ProtocolParser.java:121)
at java.lang.Thread.run(Thread.java:722)
What I'm doing wrong ?? How do I decode the data using JCodec ?
Thanks in advance.
That looks to me like no fault of your own, but rather an internal JCodec bug. You can check through the issues on their issue tracker to see if this is known. If not, you may want to create an issue for this. Provide the stack trace and as much information as you can.
Are you certain that you're getting an int array? It would appear to be a byte array from your print-out. I would suggest not doing the array conversion and also not doing a rewind; ByteBuffer.wrap will already put you at position 0 in the buffer. The 00 00 01 is a start of NAL marker and the FD is the NAL type btw.
Using Windows 7, JDK 6 (and 7).
I'm trying to get personal certificates stored in Windows MSCAPI key store and it's basic properties (in order to use private key for signing). However some aliases are identified not having private key (isKeyEntry == false) although it acctually has one.
Any suggestions how to deal with this "feature"?
The P12 file with certificate (already revoked) & private key having this weird "property" can be downloaded from http://download.upce.cz/terena-public.pfx. Password is "password".
KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
ks.load(null, null);
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = (String) aliases.nextElement();
X509CertImpl certificate = (X509CertImpl)ks.getCertificate(alias);
System.out.println("Alias: " + alias);
System.out.println(" Subject: " + certificate.getSubjectDN());
System.out.println(" Issued By: " + certificate.getIssuerDN());
if (ks.isKeyEntry(alias)) {
System.out.println(" Has private key");
}
}
I imported your pfx-file into Mozilla Thunderbird and exported it as p12-file. Now I can see it through MSCAPI. There must be something in the original certificate that prevents MSCAPI to see the private key.
I compared the files and I noticed that in the original file the Key Usage section is used.
Original pfx:
Bag Attributes
localKeyID: 01 00 00 00
friendlyName: le-b6311e84-87e7-4e02-9cf6-4012518e0541
Microsoft CSP Name: Microsoft Software Key Storage Provider
Key Attributes
X509v3 Key Usage: 90
Converted p12:
Bag Attributes
friendlyName: le-b6311e84-87e7-4e02-9cf6-4012518e0541
localKeyID: 47 E4 D3 F0 75 48 9D 77 07 E9 51 A4 F1 B6 DF E9 40 80 26 7A
Key Attributes: <No Attributes>
There are more differences in the two files, but I'm not sure which one causes the unwanted behaviour.