{"id":554,"date":"2023-09-16T17:38:01","date_gmt":"2023-09-16T09:38:01","guid":{"rendered":""},"modified":"2023-09-17T00:41:32","modified_gmt":"2023-09-16T16:41:32","slug":"js-%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%ac%e5%ad%97%e8%8a%82%e6%95%b0%e7%bb%84%ef%bc%8c%e5%ad%97%e8%8a%82%e6%95%b0%e7%bb%84%e8%bd%ac%e5%ad%97%e7%ac%a6%e4%b8%b2%ef%bc%88%e4%ba%92%e8%bd%ac%ef%bc%89","status":"publish","type":"post","link":"https:\/\/mushiming.com\/554.html","title":{"rendered":"js \u5b57\u7b26\u4e32\u8f6c\u5b57\u8282\u6570\u7ec4\uff0c\u5b57\u8282\u6570\u7ec4\u8f6c\u5b57\u7b26\u4e32\uff08\u4e92\u8f6c\uff09"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u7c7b\u4f3cjs \u4e0eJava getBytes\u4e0e\u66ff\u6362\u65b9\u6cd5<\/h2>\n

\u8fd9\u91cc\u662fJava<\/p>\n

secretKey.<\/span>getBytes<\/span>(<\/span>CHARSET_UTF8)<\/span>\n<\/code><\/pre>\n
 \/\/ \u5b57\u7b26\u4e32\u8f6c\u6570\u7ec4<\/span>\n    function<\/span> stringToByte<\/span>(<\/span>str<\/span>)<\/span> { \n   <\/span>\n        var<\/span> len,<\/span> c;<\/span>\n        len =<\/span> str.<\/span>length;<\/span>\n        var<\/span> bytes =<\/span> [<\/span>]<\/span>;<\/span>\n        for<\/span>(<\/span>var<\/span> i =<\/span> 0<\/span>;<\/span> i <<\/span> len;<\/span> i++<\/span>)<\/span> { \n   <\/span>\n            c =<\/span> str.<\/span>charCodeAt<\/span>(<\/span>i)<\/span>;<\/span>\n            if<\/span>(<\/span>c >=<\/span> 0x010000<\/span> &&<\/span> c <=<\/span> 0x10FFFF<\/span>)<\/span> { \n   <\/span>\n                bytes.<\/span>push<\/span>(<\/span>(<\/span>(<\/span>c >><\/span> 18<\/span>)<\/span> &<\/span> 0x07<\/span>)<\/span> |<\/span> 0xF0<\/span>)<\/span>;<\/span>\n                bytes.<\/span>push<\/span>(<\/span>(<\/span>(<\/span>c >><\/span> 12<\/span>)<\/span> &<\/span> 0x3F<\/span>)<\/span> |<\/span> 0x80<\/span>)<\/span>;<\/span>\n                bytes.<\/span>push<\/span>(<\/span>(<\/span>(<\/span>c >><\/span> 6<\/span>)<\/span> &<\/span> 0x3F<\/span>)<\/span> |<\/span> 0x80<\/span>)<\/span>;<\/span>\n                bytes.<\/span>push<\/span>(<\/span>(<\/span>c &<\/span> 0x3F<\/span>)<\/span> |<\/span> 0x80<\/span>)<\/span>;<\/span>\n            }<\/span> else<\/span> if<\/span>(<\/span>c >=<\/span> 0x000800<\/span> &&<\/span> c <=<\/span> 0x00FFFF<\/span>)<\/span> { \n   <\/span>\n                bytes.<\/span>push<\/span>(<\/span>(<\/span>(<\/span>c >><\/span> 12<\/span>)<\/span> &<\/span> 0x0F<\/span>)<\/span> |<\/span> 0xE0<\/span>)<\/span>;<\/span>\n                bytes.<\/span>push<\/span>(<\/span>(<\/span>(<\/span>c >><\/span> 6<\/span>)<\/span> &<\/span> 0x3F<\/span>)<\/span> |<\/span> 0x80<\/span>)<\/span>;<\/span>\n                bytes.<\/span>push<\/span>(<\/span>(<\/span>c &<\/span> 0x3F<\/span>)<\/span> |<\/span> 0x80<\/span>)<\/span>;<\/span>\n            }<\/span> else<\/span> if<\/span>(<\/span>c >=<\/span> 0x000080<\/span> &&<\/span> c <=<\/span> 0x0007FF<\/span>)<\/span> { \n   <\/span>\n                bytes.<\/span>push<\/span>(<\/span>(<\/span>(<\/span>c >><\/span> 6<\/span>)<\/span> &<\/span> 0x1F<\/span>)<\/span> |<\/span> 0xC0<\/span>)<\/span>;<\/span>\n                bytes.<\/span>push<\/span>(<\/span>(<\/span>c &<\/span> 0x3F<\/span>)<\/span> |<\/span> 0x80<\/span>)<\/span>;<\/span>\n            }<\/span> else<\/span> { \n   <\/span>\n                bytes.<\/span>push<\/span>(<\/span>c &<\/span> 0xFF<\/span>)<\/span>;<\/span>\n            }<\/span>\n        }<\/span>\n        return<\/span> bytes;<\/span>\n    }<\/span>\n\/\/ \u5b57\u7b26\u6570\u7ec4\u8f6c\u5b57\u7b26\u4e32<\/span>\n    function<\/span> Uint8ArrayToString<\/span>(<\/span>fileData<\/span>)<\/span>{ \n   <\/span>\n        var<\/span> dataString =<\/span> \"\"<\/span>;<\/span>\n        for<\/span> (<\/span>var<\/span> i =<\/span> 0<\/span>;<\/span> i <<\/span> fileData.<\/span>length;<\/span> i++<\/span>)<\/span> { \n   <\/span>\n          dataString +=<\/span> String.<\/span>fromCharCode<\/span>(<\/span>fileData[<\/span>i]<\/span>)<\/span>;<\/span>\n        }<\/span>\n       \n        return<\/span> dataString\n      \n      }<\/span>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"js \u5b57\u7b26\u4e32\u8f6c\u5b57\u8282\u6570\u7ec4\uff0c\u5b57\u8282\u6570\u7ec4\u8f6c\u5b57\u7b26\u4e32\uff08\u4e92\u8f6c\uff09js\u5b57\u7b26\u4e32\u8f6c\u5b57\u8282\u6570\u7ec4\uff0cjs\u5b57\u8282\u6570\u7ec4\u8f6c\u5b57\u7b26\u4e32_jsbyte\u6570\u7ec4\u8f6cstring","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/554"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=554"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/554\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}