I have followed all the steps exactly given in this link http://trac.pjsip.org/repos/wiki/Getting-Started/Windows-Phone, but I ended up with the following errors:
Error 1 Metadata file 'C:\Users\user\Documents\PJSIP\pjsip-apps\src\pjsua\wp\lib\PjsuaWP.BackEnd.winmd' could not be found C:\Users\user\Documents\PJSIP\pjsip-apps\src\pjsua\wp\pjsua_wp\CSC pjsua_wp
Error 2 error C1083: Cannot open include file: 'wspiapi.h': No such file or directory c:\program files (x86)\windows phone kits\8.0\include\ws2tcpip.h 1032 1 pjlib
Error 3 error C1083: Cannot open include file: 'wspiapi.h': No such file or directory c:\program files (x86)\windows phone kits\8.0\include\ws2tcpip.h 1032 1 pjlib
Error 25 error C2065: 'TLS_OUT_OF_INDEXES' : undeclared identifier c:\users\user\documents\pjsip\pjlib\src\pj\os_core_win32.c 860 1 pjlib
Error 38 error C2065: 'CONSOLE_SCREEN_BUFFER_INFO' : undeclared identifier c:\users\user\documents\pjsip\pjlib\src\pj\os_core_win32.c 1525 1 pjlib
Error 39 error C2146: syntax error : missing ';' before identifier 'info' c:\users\user\documents\pjsip\pjlib\src\pj\os_core_win32.c 1525 1 pjlib
Error 40 error C2065: 'info' : undeclared identifier c:\users\user\documents\pjsip\pjlib\src\pj\os_core_win32.c 1525 1 pjlib
Error 42 error C2065: 'info' : undeclared identifier c:\users\user\documents\pjsip\pjlib\src\pj\os_core_win32.c 1529 1 pjlib
Error 43 error C2065: 'info' : undeclared identifier c:\users\user\documents\pjsip\pjlib\src\pj\os_core_win32.c 1530 1 pjlib
Error 44 error C2224: left of '.wAttributes' must have struct/union type c:\users\user\documents\pjsip\pjlib\src\pj\os_core_win32.c 1530 1 pjlib
Error 45 error C2198: 'os_attr_to_pj_color' : too few arguments for call c:\users\user\documents\pjsip\pjlib\src\pj\os_core_win32.c 1530 1 pjlib
Error 53 error C1083: Cannot open include file: 'wspiapi.h': No such file or directory c:\program files (x86)\windows phone kits\8.0\include\ws2tcpip.h 1032 1 pjmedia
Error 75 error C2061: syntax error : identifier 'PaWinMME_GetStreamInputHandle' c:\users\user\documents\pjsip\third_party\portaudio\include\pa_win_wmme.h 154 1 libportaudio
Error 76 error C2059: syntax error : ';' c:\users\user\documents\pjsip\third_party\portaudio\include\pa_win_wmme.h 154 1 libportaudio
Error 77 error C2059: syntax error : 'type' c:\users\user\documents\pjsip\third_party\portaudio\include\pa_win_wmme.h 154 1 libportaudio
Error 78 error C2061: syntax error : identifier 'PaWinMME_GetStreamOutputHandle' c:\users\user\documents\pjsip\third_party\portaudio\include\pa_win_wmme.h 179 1 libportaudio
Error 79 error C2059: syntax error : ';' c:\users\user\documents\pjsip\third_party\portaudio\include\pa_win_wmme.h 179 1 libportaudio
Error 80 error C2059: syntax error : 'type' c:\users\user\documents\pjsip\third_party\portaudio\include\pa_win_wmme.h 179 1 libportaudio
Error 81 error C2065: 'FORMAT_MESSAGE_ALLOCATE_BUFFER' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 335 1 libportaudio
Error 86 error C2143: syntax error : missing ')' before '*' c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 524 1 libportaudio
rror 101 error C2059: syntax error : ')' c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 577 1 libportaudio
Error 104 error C2143: syntax error : missing ')' before '*' c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 638 1 libportaudio
Error 105 error C2081: 'WAVEFORMATEX' : name in formal parameter list illegal c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 638 1 libportaudio
ErroError 152 error C2224: left of '.dwFormats' must have struct/union type c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 769 1 libportaudio
Error 154 error C2065: 'QueryInputWaveFormatEx' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 772 1 libportaudio
Error 155 error C2065: 'deviceInfo' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 772 1 libportaudio
Error 156 error C2223: left of '->maxInputChannels' must point to struct/union c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 772 1 libportaudio
Error 157 error C2065: 'MMRESULT' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 820 1 libportaudio
Error 158 error C2146: syntax error : missing ';' before identifier 'mmresult' c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 820 1 libportaudio
ErrorError 180 error C2224: left of '.szPname' must have struct/union type c:\users\user\documents\pjsip\third_party\portaudio\src\hostapi\wmme\pa_win_wmme.c 853 1 libportaudio
Error 193 error C2065: 'WAVE_FORMAT_PCM' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 51 1 libportaudio
Error 194 error C2099: initializer is not a constant c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 51 1 libportaudio
Error 195 error C2065: 'WAVEFORMATEX' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 66 1 libportaudio
Error 196 error C2065: 'waveFormatEx' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 66 1 libportaudio
Error 197 error C2059: syntax error : ')' c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 66 1 libportaudio
Error 198 error C2143: syntax error : missing ';' before 'type' c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 67 1 libportaudio
or 212 error C2065: 'bytesPerFrame' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 74 1 libportaudio
Error 213 error C2065: 'waveFormatEx' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 75 1 libportaudio
Error 214 error C2223: left of '->wBitsPerSample' must point to struct/union c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 75 1 libportaudio
EError 224 error C2146: syntax error : missing ';' before identifier 'guid' c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 87 1 libportaudio
Error 225 error C2065: 'guid' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 87 1 libportaudio
Error 226 error C2065: 'waveFormatEx' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 89 1 libportaudio
Error 227 error C2223: left of '->wFormatTag' must point to struct/union c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 89 1 libportaudio
Error 228 error C2065: 'waveFormatEx' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 90 1 libportaudio
Error 229 error C2223: left of '->nChannels' must point to struct/union c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 90 1 libportaudio
or 235 error C2065: 'bytesPerFrame' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 92 1 libportaudio
Error 236 error C2065: 'waveFormatEx' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 93 1 libportaudio
Error 237 error C2223: left of '->nBlockAlign' must point to struct/union c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 93 1 libportaudio
Error 238 error C2065: 'bytesPerFrame' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 93 1 libportaudio
Error 239 error C2065: 'waveFormatEx' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 94 1 libportaudio
Error 240 error C2223: left of '->wBitsPerSample' must point to struct/union c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 94 1 libportaudio
Error 241 error C2065: 'bytesPerSample' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 94 1 libportaudio
Error 242 error C2065: 'waveFormatEx' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 95 1 libportaudio
Error 243 error C2223: left of '->cbSize' must point to struct/union c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 95 1 libportaudio
Error 244 error C2065: 'waveFormatEx' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 98 1 libportaudio
Error 245 error C2223: left of '->wBitsPerSample' must point to struct/union c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 98 1 libportaudio
Error 246 error C2065: 'guid' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 102 1 libportaudio
Error 247 error C2440: '=' : cannot convert from 'GUID' to 'int' c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 102 1 libportaudio
Error 248 error C2065: 'guid' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 103 1 libportaudio
Error 249 error C2224: left of '.Data1' must have struct/union type c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 103 1 libportaudio
Error 250 error C2065: 'guid' : undeclared identifier c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 104 1 libportaudio
Error 251 error C2440: '=' : cannot convert from 'int' to 'GUID' c:\users\user\documents\pjsip\third_party\portaudio\src\os\win\pa_win_waveformat.c 104 1 libportaudio
Error 252 error LNK1181: cannot open input file 'C:\Users\user\Documents\PJSIP\pjlib-util\lib\pjlib-util-i386-Win32-vc11-Debug.lib' C:\Users\user\Documents\PJSIP\pjsip-apps\build\LINK libpjproject
Error 253 error U1073: don't know how to make '..\..\pjsip\lib\pjsip-core-i386-win32-vc11-debug.lib' C:\Users\user\Documents\PJSIP\pjsip-apps\build\NMAKE samples
Error 254 error MSB3073: The command "nmake /NOLOGO /S /f Samples-vc.mak BUILD_MODE=debug VC_VER=11 ARCH=win32 /a" exited with code 2. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.MakeFile.Targets 43 5 samples
Error 255 error LNK1104: cannot open file 'iphlpapi.lib' C:\Users\user\Documents\PJSIP\pjsip-apps\build\LINK sample_debug
Error 256 error C1083: Cannot open include file: 'wspiapi.h': No such file or directory c:\program files (x86)\windows phone kits\8.0\include\ws2tcpip.h
Please help me to solve this problem
Thanks in advance
I suggest you switch to Windows Runtime. There's a work to do but all this issues can be solved. I'm succesfully using pjsip in Universal App with some small changes.
One of your troubles is that you're compiling portaudio. Follow the guideline:
#define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO 0
#define PJMEDIA_AUDIO_DEV_HAS_WMME 0
#define PJMEDIA_AUDIO_DEV_HAS_WASAPI 1
But that's only the first step
Related
I'm trying to make a dataframe from a json file without success. I'm not exactly sure why, as is my first time dealing with json files, but from what I found while looking for a solution it seems the data is heavily nested.
Here's the json https://stats.nba.com/stats/leagueLeaders?ActiveFlag=No&LeagueID=00&PerMode=Totals&Scope=S&Season=All+Time&SeasonType=Regular+Season&StatCategory=AST.
I've tried to create the df using pandas .read_json() with different orients, with open, and also using request. The request method actually gave me a dataframe although highly unconfigured.
AST_LDR = pd.read_json('C:\\Users\\user\\Desktop\\python\\AssistLeaders.json')
#Error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-20-55a99c3e3802> in <module>
----> 1 AST_LDR = pd.read_json('C:\\Users\\user\\Desktop\\python\\Kobe Bryant\\AssistLeaders.json')
2
3
~\Anaconda3\lib\site-packages\pandas\io\json\json.py in read_json(path_or_buf, orient, typ, dtype, convert_axes, convert_dates, keep_default_dates, numpy, precise_float, date_unit, encoding, lines, chunksize, compression)
425 return json_reader
426
--> 427 result = json_reader.read()
428 if should_close:
429 try:
~\Anaconda3\lib\site-packages\pandas\io\json\json.py in read(self)
535 )
536 else:
--> 537 obj = self._get_object_parser(self.data)
538 self.close()
539 return obj
~\Anaconda3\lib\site-packages\pandas\io\json\json.py in _get_object_parser(self, json)
554 obj = None
555 if typ == 'frame':
--> 556 obj = FrameParser(json, **kwargs).parse()
557
558 if typ == 'series' or obj is None:
~\Anaconda3\lib\site-packages\pandas\io\json\json.py in parse(self)
650
651 else:
--> 652 self._parse_no_numpy()
653
654 if self.obj is None:
~\Anaconda3\lib\site-packages\pandas\io\json\json.py in _parse_no_numpy(self)
869 if orient == "columns":
870 self.obj = DataFrame(
--> 871 loads(json, precise_float=self.precise_float),
dtype=None)
872 elif orient == "split":
873 decoded = {str(k): v for k, v in compat.iteritems(
ValueError: Expected object or value
#------------
import json
with open('C:\\Users\\user\\Desktop\\python\\Kobe Bryant\\AssistLeaders.json') as f:
data = json.load(f)
AST_LDR = pd.DataFrame(data)
#Error
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-19-f61dd4edbb9e> in <module>
1 import json
2 with open('C:\\Users\\user\\Desktop\\python\\Kobe Bryant\\AssistLeaders.json') as f:
----> 3 data = json.load(f)
4 AST_LDR = pd.DataFrame(data)
~\Anaconda3\lib\json\__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
294 cls=cls, object_hook=object_hook,
295 parse_float=parse_float, parse_int=parse_int,
--> 296 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
297
298
~\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
~\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
~\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
JSON is a very flexible format. pd.read_json accepts only a few formats and more often than not, the actual data does not fit any of those. You are better off treating it as a dictionary, extracting the needed data and construct your data frame accordingly:
url = 'https://stats.nba.com/stats/leagueLeaders?ActiveFlag=No&LeagueID=00&PerMode=Totals&Scope=S&Season=All+Time&SeasonType=Regular+Season&StatCategory=AST'
data = requests.get(url).json()
df = pd.DataFrame(data['resultSet']['rowSet'], columns=data['resultSet']['headers'])
Result:
PLAYER_ID PLAYER_NAME GP MIN FGM FGA FG_PCT FG3M FG3A FG3_PCT FTM FTA FT_PCT OREB DREB REB AST STL BLK TOV PF PTS AST_TOV STL_TOV EFG_PCT TS_PCT GP_RANK MIN_RANK FGM_RANK FGA_RANK FG_PCT_RANK FG3M_RANK FG3A_RANK FG3_PCT_RANK FTM_RANK FTA_RANK FT_PCT_RANK OREB_RANK DREB_RANK REB_RANK AST_RANK STL_RANK BLK_RANK TOV_RANK PF_RANK PTS_RANK AST_TOV_RANK STL_TOV_RANK EFG_PCT1 TS_PCT1
0 304 John Stockton 1504 47766 7039 13658 0.515 845.0 2202.0 0.384 4788 5796 0.826 966.0 3085.0 4051 15806 3265.0 315.0 4244.0 3942 19711 3.724 0.769 0.546 0.608 4 9 69 93 109 153 169 88 40 48 183 407 246 371 1 1 400 2 14 45 5 164 50 18
1 467 Jason Kidd 1391 50116 6219 15557 0.400 1988.0 5701.0 0.349 3103 3954 0.785 1768.0 6957.0 8725 12091 2684.0 450.0 4003.0 2572 17529 3.020 0.670 0.464 0.507 11 5 101 56 1190 10 7 293 149 152 447 138 27 56 2 2 284 5 171 85 30 275 881 888
2 959 Steve Nash 1217 38073 6321 12892 0.490 1685.0 3939.0 0.428 3060 3384 0.904 643.0 2999.0 3642 10335 899.0 102.0 3478.0 1982 17387 2.972 0.258 0.556 0.605 36 46 96 116 267 22 35 13 154 221 3 601 262 436 3 222 861 13 411 87 37 1030 32 22
3 349 Mark Jackson 1296 39117 4793 10731 0.447 734.0 2213.0 0.332 2169 2818 0.770 1281.0 3682.0 4963 10334 1608.0 117.0 3155.0 2230 12489 3.275 0.510 0.481 0.522 23 38 227 207 748 193 165 413 324 322 561 273 176 257 4 32 806 23 289 223 19 571 650 679
4 77142 Magic Johnson 906 33245 6211 11951 0.520 325.0 1074.0 0.303 4960 5850 0.848 1601.0 4958.0 6559 10141 1724.0 374.0 3506.0 2050 17707 2.892 0.492 0.533 0.610 227 98 102 145 91 392 369 520 37 45 91 180 80 138 5 21 345 11 368 80 46 625 98 16
I have a tls file such as:
1224 926 1380 688 845 109 118 88 1275 1306 91 796 102 1361 27 995
1928 2097 138 1824 198 117 1532 2000 1478 539 1982 125 1856 139 475 1338
848 202 1116 791 1114 236 183 186 150 1016 1258 84 952 1202 988 866
946 155 210 980 896 875 925 613 209 746 147 170 577 942 475 850
1500 322 43 95 74 210 1817 1631 1762 128 181 716 171 1740 145 1123
3074 827 117 2509 161 206 2739 253 2884 248 3307 2760 2239 1676 1137 3055
183 85 143 197 243 72 291 279 99 189 30 101 211 209 77 198
175 149 259 372 140 250 168 142 146 284 273 74 162 112 78 29
169 578 97 589 473 317 123 102 445 217 144 398 510 464 247 109
3291 216 185 1214 167 495 1859 194 1030 3456 2021 1622 3511 222 3534 1580
2066 2418 2324 93 1073 82 102 538 1552 962 91 836 1628 2154 2144 1378
149 963 1242 849 726 1158 164 1134 658 161 1148 336 826 1303 811 178
3421 1404 2360 2643 3186 3352 1112 171 168 177 146 1945 319 185 2927 2289
543 462 111 459 107 353 2006 116 2528 56 2436 1539 1770 125 2697 2432
1356 208 5013 4231 193 169 3152 2543 4430 4070 4031 145 4433 4187 4394 1754
5278 113 4427 569 5167 175 192 3903 155 1051 4121 5140 2328 203 5653 3233
how can I read it in a list of list of int in haskell?
I have tried few options but I could not manage to do it. I am very new to haskell so please be patience.
First break your input into lines using lines:
let test = "1 2 3 4\n 5 6 7 \n 4 2 5"
let rows = lines test --literally "lines test"! Beautiful, eh?
Result:
["1 2 3 4"," 5 6 7 "," 4 2 5"] :: [[Char]]
Then, extract individual numbers as strings using words:
let nums_as_strings = map words rows
Result:
[["1","2","3","4"],["5","6","7"],["4","2","5"]] :: :: [[[Char]]]
The last thing to do is convert these strings to integers with read:
let numbers = map (map read) nums_as_strings :: [[Int]]
Result:
[[1,2,3,4],[5,6,7],[4,2,5]] :: [[Int]]
Or, squashed into one line:
let numbers = map (map read) (map words $ lines test) :: [[Int]]
Example with your data:
Prelude> let test = "1224 926 1380 688 845 109 118 88 1275 1306 91 796 102 1361 27 995\n1928 2097 138 1824 198 117 1532 2000 1478 539 1982 125 1856 139 475 1338"
Prelude> map (map read) (map words $ lines test) :: [[Int]]
[[1224,926,1380,688,845,109,118,88,1275,1306,91,796,102,1361,27,995],[1928,2097,138,1824,198,117,1532,2000,1478,539,1982,125,1856,139,475,1338]]
You may need to take care of empty lines, but that's really simple.
import System.IO
readListOfLists :: Handle -> IO [[Int]]
readListOfLists handle = do
contents <- hGetContents handle
let ls :: [String]
ls = lines contents
ws :: [[String]]
ws= map words ls
res :: [[Int]]
res = map (map read) ws
return res;
or you can write the same code in one line:
readListOfLists :: Handle -> IO [[Int]]
readListOfLists = fmap (map (map read . words) . lines) . hGetContents
To use it:
do
handle <- openFile fileName ReadMode
table <- readListOfLists handle
hClose handle
print table
I am working on verifying the access token on AWS Cognito. One thing I have to do is to convert the key from jwks.json (of the userpool) into a rsa Public Key structure (depending on the used JWT API).
So the values for 'n' and 'e' must be big int (long) and int.
What would be the proper value of those two variables, for example:
raw_n := "rdTmzrh7t0i_YN0MDLejnS0jXIFoSzRfFEbqf-bwGuRLnhLI4T3zGAk9HGZeAG6B5gg1D40Jsz1upo4E70VS0raGfSBPYPO7ZAJ2VCUUeblr9X_aWK4f294v4Cf3n8jZyFcGK9qhgcqy3DlHqqDANtjamWVtEhTRTFc-qoz1ScvHmPupsXlj1FsAEFEbVhP4705ez5gW3uQOoidrm38sPFwCN7g7xhA9CyzF04Zsjky55OfMCyWlIt7nljLx7ZRG3dVRD3vdEBI99qtxf43qMCWSPUk7Whn11Wf_u0xDrWhtGR9k599rKBBRWuqcujYYnFuOT0BeQIL25cePPK8lxw"
raw_e := "AQAB"
I suppose this is Base64 URL encoded.
I am using Go and when decoding them, I am having those values:
Value of N = 21944212446918148307583266513211511961176501179660110972882270757464120247554839864039423096862533136364974693915136668416630333929475539217929135693935014796040215031370110392351836608149288005498214604075814317642291632460369313969964278103135047317799644939426174469533574133378199425168189176269507635563270873057483981163804984573367938044175828995131343800369166239708527999544583873649523245709447765091038652758632917341001616695912404965678061555823269517387737693508193881028187912513285002546706797506255288735805912213209305939523528571103281920754204216834697552752238593850648051945624431639572960454087
Value of E = 65537
And the final values are:
TokenSignature= GYZQKv7o8_o9E4ktVKZngYD4BS5QluOMwE-MRcJB432CmNimQm6JbvT3H48ECThe4f3sZ1KyVbgDJbyUnlkaAwMEBjMnlV7AUaZb-ifveM7kHM30BS5LCV_SCiCk-PvmWjeIHu9bR3EwG8azJCceD5A7gDLmhAtPN94gRy-opXJPAnaCba00AwKBd_pN3UH7LYu4u4EQ29eIfn4k4RCLuR31jr7ad3dvvjhhy658dQSHzSuPZGcN1-CRVSlrd0nk0Ba2t8W33LtjxM6wzPThWgh0fpy2XEDosGU_9FiXdEjUKisE3VHxroygQ8ekVWKHssa2eujXCx8OthWzaGag0w1
Signing String= eyJhbGciOiJSUzI1NiIsImtpZCI6ImpBNlFvakp0RkI0TmNIR1BmcS85ZWgzSHI2YnVXWEI0VzkxRTd5bWNjSk09In0.eyJleHAiOjE0NzAyNzgzMTEsInRva2VuX3VzZSI6ImFjY2VzcyIsImlzcyI6Imh0dHBzOi8vY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb20vdXMtZWFzdC0xX0d1OFlhVGg3MiIsImNsaWVudF9pZCI6IjRwNzNuYjhra3NsbHJrbTlzMzdzYXZsNzEzIiwidXNlcm5hbWUiOiJtYXRlbyIsImtpZCI6IiIsImFsZyI6IiIsImp0aSI6IjhmNTBiZmU4LWVlNGUtNGFkZi04MDQxLWU5MGM4YWJkZDExZCIsImlhdCI6MTQ3MDI3NDcxMSwic3ViIjoiYjFjMDZhMTktYjE5Yy00NGMwLTgzZjctODY2NTZjYzRmMjMxIn0
rsa.PublicKey{N:21944212446918148307583266513211511961176501179660110972882270757464120247554839864039423096862533136364974693915136668416630333929475539217929135693935014796040215031370110392351836608149288005498214604075814317642291632460369313969964278103135047317799644939426174469533574133378199425168189176269507635563270873057483981163804984573367938044175828995131343800369166239708527999544583873649523245709447765091038652758632917341001616695912404965678061555823269517387737693508193881028187912513285002546706797506255288735805912213209305939523528571103281920754204216834697552752238593850648051945624431639572960454087, E:65537}
However, with those revisiter values, I am still getting crypto/rsa: verification error. How can I determine if the problem is coming from the JWT Library or the values?
Thank you very much
You should be able to verify the signature with the rsa.PublicKey generated by the program below or at https://play.golang.org/p/VZqD5m057b. It is based on code from https://github.com/mendsley/gojwk (please see the playground link or https://github.com/mendsley/gojwk/blob/master/LICENSE for the Copyright attribution) - I would recommend to clone that repository and use it as an example and model.
package main
import (
"crypto/rsa"
"encoding/base64"
"encoding/binary"
"fmt"
"math/big"
)
func main() {
rawN := "rdTmzrh7t0i_YN0MDLejnS0jXIFoSzRfFEbqf-bwGuRLnhLI4T3zGAk9HGZeAG6B5gg1D40Jsz1upo4E70VS0raGfSBPYPO7ZAJ2VCUUeblr9X_aWK4f294v4Cf3n8jZyFcGK9qhgcqy3DlHqqDANtjamWVtEhTRTFc-qoz1ScvHmPupsXlj1FsAEFEbVhP4705ez5gW3uQOoidrm38sPFwCN7g7xhA9CyzF04Zsjky55OfMCyWlIt7nljLx7ZRG3dVRD3vdEBI99qtxf43qMCWSPUk7Whn11Wf_u0xDrWhtGR9k599rKBBRWuqcujYYnFuOT0BeQIL25cePPK8lxw"
rawE := "AQAB"
decodedE, err := base64.RawURLEncoding.DecodeString(rawE)
if err != nil {
panic(err)
}
// make sure that the E field is at least 4 bytes, pad if necessary
if len(decodedE) < 4 {
ndata := make([]byte, 4)
copy(ndata[4-len(decodedE):], decodedE)
decodedE = ndata
}
pubKey := &rsa.PublicKey{
N: &big.Int{},
E: int(binary.BigEndian.Uint32(decodedE[:])),
}
decodedN, err := base64.RawURLEncoding.DecodeString(rawN)
if err != nil {
panic(err)
}
pubKey.N.SetBytes(decodedN)
fmt.Println(decodedN)
fmt.Println(decodedE)
fmt.Printf("%#v\n", *pubKey)
}
Output:
[173 212 230 206 184 123 183 72 191 96 221 12 12 183 163 157 45 35 92 129 104 75 52 95 20 70 234 127 230 240 26 228 75 158 18 200 225 61 243 24 9 61 28 102 94 0 110 129 230 8 53 15 141 9 179 61 110 166 142 4 239 69 82 210 182 134 125 32 79 96 243 187 100 2 118 84 37 20 121 185 107 245 127 218 88 174 31 219 222 47 224 39 247 159 200 217 200 87 6 43 218 161 129 202 178 220 57 71 170 160 192 54 216 218 153 101 109 18 20 209 76 87 62 170 140 245 73 203 199 152 251 169 177 121 99 212 91 0 16 81 27 86 19 248 239 78 94 207 152 22 222 228 14 162 39 107 155 127 44 60 92 2 55 184 59 198 16 61 11 44 197 211 134 108 142 76 185 228 231 204 11 37 165 34 222 231 150 50 241 237 148 70 221 213 81 15 123 221 16 18 61 246 171 113 127 141 234 48 37 146 61 73 59 90 25 245 213 103 255 187 76 67 173 104 109 25 31 100 231 223 107 40 16 81 90 234 156 186 54 24 156 91 142 79 64 94 64 130 246 229 199 143 60 175 37 199]
[0 1 0 1]
rsa.PublicKey{N:21944212446918148307583266513211511961176501179660110972882270757464120247554839864039423096862533136364974693915136668416630333929475539217929135693935014796040215031370110392351836608149288005498214604075814317642291632460369313969964278103135047317799644939426174469533574133378199425168189176269507635563270873057483981163804984573367938044175828995131343800369166239708527999544583873649523245709447765091038652758632917341001616695912404965678061555823269517387737693508193881028187912513285002546706797506255288735805912213209305939523528571103281920754204216834697552752238593850648051945624431639572960454087, E:65537}
I have used npm module jwk-to-pem in my nodeJS app. As seen in the documentation:
var jwkToPem = require('jwk-to-pem'),
jwt = require('jsonwebtoken');
var jwk = { kty: 'EC', crv: 'P-256', x: '...', y: '...' },
pem = jwkToPem(jwk);
jwt.verify(token, pem);
You can export pem to a file and use it in your code.
Decoding a JWK into a *rsa.PublicKey can be done by unmarshing the JSON into the following data structure and using the method below.
A link to this data structure:
// JSONKey represents a raw key inside a JWKs.
type JSONKey struct {
Curve string `json:"crv"`
Exponent string `json:"e"`
ID string `json:"kid"`
Modulus string `json:"n"`
X string `json:"x"`
Y string `json:"y"`
precomputed interface{}
}
A link to this method:
// RSA parses a JSONKey and turns it into an RSA public key.
func (j *JSONKey) RSA() (publicKey *rsa.PublicKey, err error) {
// Check if the key has already been computed.
if j.precomputed != nil {
var ok bool
if publicKey, ok = j.precomputed.(*rsa.PublicKey); ok {
return publicKey, nil
}
}
// Confirm everything needed is present.
if j.Exponent == "" || j.Modulus == "" {
return nil, fmt.Errorf("%w: rsa", ErrMissingAssets)
}
// Decode the exponent from Base64.
//
// According to RFC 7518, this is a Base64 URL unsigned integer.
// https://tools.ietf.org/html/rfc7518#section-6.3
var exponent []byte
if exponent, err = base64.RawURLEncoding.DecodeString(j.Exponent); err != nil {
return nil, err
}
// Decode the modulus from Base64.
var modulus []byte
if modulus, err = base64.RawURLEncoding.DecodeString(j.Modulus); err != nil {
return nil, err
}
// Create the RSA public key.
publicKey = &rsa.PublicKey{}
// Turn the exponent into an integer.
//
// According to RFC 7517, these numbers are in big-endian format.
// https://tools.ietf.org/html/rfc7517#appendix-A.1
publicKey.E = int(big.NewInt(0).SetBytes(exponent).Uint64())
// Turn the modulus into a *big.Int.
publicKey.N = big.NewInt(0).SetBytes(modulus)
// Keep the public key so it won't have to be computed every time.
j.precomputed = publicKey
return publicKey, nil
}
If you're looking to authenticate JWTs from a JWKs resource like AWS Cognito, I took these examples from a project that does just that: github.com/MicahParks/keyfunc
I use a Golang HTTP request to get json output as follow.
The web service I am trying to access is Micrsoft Translator https://msdn.microsoft.com/en-us/library/dn876735.aspx
//Data struct of TransformTextResponse
type TransformTextResponse struct {
ErrorCondition int `json:"ec"` // A positive number representing an error condition
ErrorDescriptive string `json:"em"` // A descriptive error message
Sentence string `json:"sentence"` // transformed text
}
//some code ....
body, err := ioutil.ReadAll(response.Body)
defer response.Body.Close()
if err != nil {
return "", tracerr.Wrap(err)
}
transTransform = TransformTextResponse{}
err = json.Unmarshal(body, &transTransform)
if err != nil {
return "", tracerr.Wrap(err)
}
I got an error from invalid character 'ï' looking for beginning of value
So, I try to print the body as string fmt.Println(string(body)), it show:
{"ec":0,"em":"OK","sentence":"This is too strange i just want to go home soon"}
It seems the data doesn't have any problem, so I tried to create the same value by jason.Marshal
transTransform := TransformTextResponse{}
transTransform.ErrorCondition = 0
transTransform.ErrorDescriptive = "OK"
transTransform.Sentence = "This is too strange i just want to go home soon"
jbody, _ := json.Marshal(transTransform)
I found the original data might have problem, so I try to compare two data in []byte format.
Data from response.Body:
[239 187 191 123 34 101 99 34 58 48 44 34 101 109 34 58 34 79 75 34 44 34 115 101 110 116 101 110 99 101 34 58 34 84 104 105 115 32 105 115 32 116 111 111 32 115 116 114 97 110 103 101 32 105 32 106 117 115 116 32 119 97 110 116 32 116 111 32 103 111 32 104 111 109 101 32 115 111 111 110 34 125]
Data from json.Marshal
[123 34 101 99 34 58 48 44 34 101 109 34 58 34 79 75 34 44 34 115 101 110 116 101 110 99 101 34 58 34 84 104 105 115 32 105 115 32 116 111 111 32 115 116 114 97 110 103 101 32 105 32 106 117 115 116 32 119 97 110 116 32 116 111 32 103 111 32 104 111 109 101 32 115 111 111 110 34 125]
Any idea how I parse this response.Body and Unmarshal it into data structure?
The server is sending you a UTF-8 text string with a Byte Order Mark (BOM). The BOM identifies that the text is UTF-8 encoded, but it should be removed before decoding.
This can be done with the following line (using package "bytes"):
body = bytes.TrimPrefix(body, []byte("\xef\xbb\xbf")) // Or []byte{239, 187, 191}
PS. The error referring to ï is because the UTF-8 BOM interpreted as an ISO-8859-1 string will produce the characters .
I originally posted this at Super User, but now think it should be here instead...
I'm trying to port my RoR webapp over to a DreamHost VPS. I've upgraded the VPS --> Ruby 1.9.2 from 1.8.7 and am using Rails 3.0.1 and the mysql2 (0.2.6) gem. I'm getting the following error when trying to start mongrel:
/usr/bin/ruby1.8: symbol lookup error: /home/USERNAME/.gems/gems/mysql2-0.2.6/lib/mysql2/mysql2.so: undefined symbol: rb_intern2
...so I tried using the mysql (2.8.1) gem instead and get the following error:
wrong argument type Mysql (expected Struct) (TypeError)
0 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/mysql_adapter.rb 600 in real_connect'
1 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/mysql_adapter.rb 600 inconnect'
2 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/mysql_adapter.rb 164 in initialize'
3 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/mysql_adapter.rb 36 innew'
4 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/mysql_adapter.rb 36 in mysql_connection'
5 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb 230 insend'
6 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb 230 in new_connection'
7 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb 238 incheckout_new_connection'
8 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb 194 in checkout'
9 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb 190 inloop'
10 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb 190 in checkout'
11 /usr/lib/ruby/1.8/monitor.rb 242 insynchronize'
12 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb 189 in checkout'
13 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb 96 inconnection'
14 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb 318 in retrieve_connection'
15 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb 97 inretrieve_connection'
16 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb 89 in connection'
17 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/associations.rb 1804 increate_has_and_belongs_to_many_reflection'
18 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/associations.rb 1411 in has_and_belongs_to_many'
19 /home/USERNAME/.gems/gems/activerecord-3.0.1/lib/active_record/autosave_association.rb 137 inhas_and_belongs_to_many'
20 /home/USERNAME/portfoliofinearts.ca/farr/app/models/project.rb 3
21 /home/USERNAME/.gems/gems/activesupport-3.0.1/lib/active_support/dependencies.rb 239 in require'
22 /home/USERNAME/.gems/gems/activesupport-3.0.1/lib/active_support/dependencies.rb 239 inrequire'
23 /home/USERNAME/.gems/gems/activesupport-3.0.1/lib/active_support/dependencies.rb 227 in load_dependency'
24 /home/USERNAME/.gems/gems/activesupport-3.0.1/lib/active_support/dependencies.rb 239 inrequire'
25 /home/USERNAME/.gems/gems/activesupport-3.0.1/lib/active_support/dependencies.rb 346 in require_or_load'
26 /home/USERNAME/.gems/gems/activesupport-3.0.1/lib/active_support/dependencies.rb 300 independ_on'
27 /home/USERNAME/.gems/gems/activesupport-3.0.1/lib/active_support/dependencies.rb 216 in require_dependency'
28 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/engine.rb 138 ineager_load!'
29 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/engine.rb 137 in each'
30 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/engine.rb 137 ineager_load!'
31 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/engine.rb 135 in each'
32 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/engine.rb 135 ineager_load!'
33 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/application.rb 108 in eager_load!'
34 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/application/finisher.rb 41
35 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/initializable.rb 25 ininstance_exec'
36 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/initializable.rb 25 in run'
37 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/initializable.rb 50 inrun_initializers'
38 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/initializable.rb 49 in each'
39 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/initializable.rb 49 inrun_initializers'
40 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/application.rb 134 in initialize!'
41 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/application.rb 77 insend'
42 /home/USERNAME/.gems/gems/railties-3.0.1/lib/rails/application.rb 77 in method_missing'
43 /home/USERNAME/mydomain.com/test_app/config/environment.rb 10
44 /usr/lib/ruby/1.8/rubygems/custom_require.rb 31 ingem_original_require'
45 /usr/lib/ruby/1.8/rubygems/custom_require.rb 31 in require'
46 config.ru 3
47 /usr/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/builder.rb 46 ininstance_eval'
48 /usr/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/builder.rb 46 in initialize'
49 config.ru 1 innew'
50 config.ru 1
I'd prefer to use mysql2, so that's the preferred solution I'm looking for, but I will certainly appreciate input on either problem.
I'm not encountering any problems such as this in my development environment (which is windows)
You'd mentioned that you're running Ruby 1.9.2 but your error dump looks like it's running Ruby 1.8 I'm not sure that this would cause the problem or not but it seems like a potential issue.
I'd uninstall ruby1.8 and see if it fixes anything.
sudo apt-get remove ruby1.8