当前位置:网站首页>Record a bug caused by a line break

Record a bug caused by a line break

2022-06-27 00:40:00 Hua Weiyun

I'm learning java since , It's worth a lot \n As a newline , Sometimes I see that the line break character in some places is \r\n, I didn't care .
But in a project , I need to request a certificate from an interface , And then put the string of the certificate , Encapsulation head and tail , There is a file .
The certificate is about the following .
 Insert picture description here
What I ask the interface to get is the intermediate string , The first and last lines are added manually .
The code is as follows :
 Insert picture description here
This certificate is crt Format , I still need it openssl Put this crt Certificate conversion p12 certificate .
As a result, when I execute the conversion command , give the result as follows :
 Insert picture description here

Prompt certificate not found , Later, I copied the contents of this certificate to other files , To perform , It can be parsed again .
 Insert picture description here
I can't figure out why , The contents of the two documents are exactly the same , But a certificate can resolve , One can't .
Later, carefully compare the contents of the two certificates , There is still a little difference .
 Insert picture description here
The newline character of a certificate takes up one byte , The other takes up two bytes .

Later, I learned from the information that ,
enter :Carriage Return Use escape characters ’\r’ Express , It's obvious that the 2 The first letter of a word .

Line break :New Line Use escape characters ’\n’ Express , It's obvious that the 1 The first letter of a word .
Windows Inside the system , Each line ends with “< Line break >< enter >”, namely “\n\r”; If you use a new line in the following file \n, There may be unexpected mistakes .

Change the code to :
 Insert picture description here

原网站

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270004260509.html