File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
src/libraries/Common/tests/System/Security/Cryptography Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -109,8 +109,26 @@ internal static string PemEncode(string label, byte[] data)
109
109
#if NET
110
110
return PemEncoding . WriteString ( label , data ) ;
111
111
#else
112
- return
113
- $ "-----BEGIN { label } -----\n { Convert . ToBase64String ( data , Base64FormattingOptions . InsertLineBreaks ) } \n -----END { label } -----";
112
+ StringBuilder sb = new StringBuilder ( ) ;
113
+
114
+ sb . Append ( "-----BEGIN " ) ;
115
+ sb . Append ( label ) ;
116
+ sb . Append ( "-----\n " ) ;
117
+
118
+ string base64 = Convert . ToBase64String ( data ) ;
119
+
120
+ for ( int i = 0 ; i < base64 . Length ; i += 64 )
121
+ {
122
+ int len = Math . Min ( 64 , base64 . Length - i ) ;
123
+ sb . Append ( base64 , i , len ) ;
124
+ sb . Append ( '\n ' ) ;
125
+ }
126
+
127
+ sb . Append ( "-----END " ) ;
128
+ sb . Append ( label ) ;
129
+ sb . Append ( "-----" ) ;
130
+
131
+ return sb . ToString ( ) ;
114
132
#endif
115
133
}
116
134
}
You can’t perform that action at this time.
0 commit comments