将byte []附加到另一个byte []的末尾 [英] Appending a byte[] to the end of another byte[]
本文介绍了将byte []附加到另一个byte []的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个长度未知的 byte []
数组,我只想将一个附加到另一个的末尾,即:
I have two byte[]
arrays which are of unknown length and I simply want to append one to the end of the other, i.e.:
byte[] ciphertext = blah;
byte[] mac = blah;
byte[] out = ciphertext + mac;
我尝试过使用 arraycopy()
但是似乎无法让它发挥作用。
I have tried using arraycopy()
but can't seem to get it to work.
推荐答案
使用 System.arraycopy()
,类似以下内容应该有效:
Using System.arraycopy()
, something like the following should work:
// create a destination array that is the size of the two arrays
byte[] destination = new byte[ciphertext.length + mac.length];
// copy ciphertext into start of destination (from pos 0, copy ciphertext.length bytes)
System.arraycopy(ciphertext, 0, destination, 0, ciphertext.length);
// copy mac into end of destination (from pos ciphertext.length, copy mac.length bytes)
System.arraycopy(mac, 0, destination, ciphertext.length, mac.length);
这篇关于将byte []附加到另一个byte []的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文