RSA 公钥长度读写



 

 

读取长度:

this.length = DerInputStream.getLength(i & 0xFF, paramInputStream);

 

static int getLength(int paramInt, InputStream paramInputStream)
  throws IOException
{
  int j = paramInt;    int i;
  if ((j & 0x80) == 0) {
    i = j;
  } else {
    j &= 127;



    if (j == 0)
      return -1;
    if ((j < 0) || (j > 4)) {
      throw new IOException("DerInputStream.getLength(): lengthTag=" + j + ", " + ((j < 0) ? "incorrect DER encoding." : "too big."));

    }

    for (i = 0; j > 0; --j) {
      i <<= 8;
      i += (0xFF & paramInputStream.read());
    }
  }
  return i;
}

 

写入长度:

public void putLength(int paramInt)
  throws IOException
{
  if (paramInt < 128) {
    write((byte)paramInt);
  }
  else if (paramInt < 256) {
    write(-127);
    write((byte)paramInt);
  }
  else if (paramInt < 65536) {
    write(-126);
    write((byte)(paramInt >> 8));
    write((byte)paramInt);
  }
  else if (paramInt < 16777216) {
    write(-125);
    write((byte)(paramInt >> 16));
    write((byte)(paramInt >> 8));
    write((byte)paramInt);
  }
  else {
    write(-124);
    write((byte)(paramInt >> 24));
    write((byte)(paramInt >> 16));
    write((byte)(paramInt >> 8));
    write((byte)paramInt);
  }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值