Initialize the public key from a blob of binary data.

@param blob
byte[]
@param start
int
@param len
int
@throws SshException
@todo Implement this com.sshtools.ssh.SshPublicKey method
172354
public void init(byte[] blob, int start, int len) throws SshException {

		ByteArrayReader bar = new ByteArrayReader(blob, start, len);

		try {
			DSAPublicKeySpec dsaKey;

			// Extract the key information
			String header = bar.readString();

			if (!header.equals(getAlgorithm())) {
				throw new SshException("The encoded key is not DSA",
						SshException.INTERNAL_ERROR);
			}

			BigInteger p = bar.readBigInteger();
			BigInteger q = bar.readBigInteger();
			BigInteger g = bar.readBigInteger();
			BigInteger y = bar.readBigInteger();
			dsaKey = new DSAPublicKeySpec(y, p, q, g);

			KeyFactory kf = JCEProvider
					.getProviderForAlgorithm(JCEAlgorithms.JCE_DSA) == null ? KeyFactory
					.getInstance(JCEAlgorithms.JCE_DSA) : KeyFactory
					.getInstance(JCEAlgorithms.JCE_DSA, JCEProvider
							.getProviderForAlgorithm(JCEAlgorithms.JCE_DSA));
			pubkey = (DSAPublicKey) kf.generatePublic(dsaKey);

		} catch (Exception ex) {
			throw new SshException(
					"Failed to obtain DSA key instance from JCE",
					SshException.INTERNAL_ERROR, ex);

		} finally {
			try {
				bar.close();
			} catch (IOException e) {
			}
		}
	}
1305760
protected void loadCipherToBit() {
        boolean keySizeFromCipherMap =
                        Boolean.valueOf(WebContainer.getWebContainerProperties().getProperty("com.ibm.ws.webcontainer.keysizefromciphermap", "true")).booleanValue();
        //721610
        if (keySizeFromCipherMap) {
            this.getKeySizefromCipherMap("toLoad"); // this will load the Map with values
        } else {
            Properties cipherToBitProps = new Properties();

            // load the ssl cipher suite bit sizes property file
            try {
                String fileName = System.getProperty("server.root") + File.separator + "properties" + File.separator + "sslbitsizes.properties";

                cipherToBitProps.load(new FileInputStream(fileName));
            } catch (Exception ex) {
                logger.logp(Level.SEVERE, CLASS_NAME, "loadCipherToBit", "failed.to.load.sslbitsizes.properties ", ex); /* 283348.1 */
                com.ibm.wsspi.webcontainer.util.FFDCWrapper.processException(ex, CLASS_NAME + ".loadCipherToBit", "825", this);
            }

            // put the properties into a hash map for unsynch. reference
            _cipherToBit.putAll(cipherToBitProps);
        }
    }
236456
public static int crypto_sign_open(
  Sha512 sha512provider,
  byte[] m, long mlen,
  byte[] sm, long smlen,
  byte[] pk
)
{
  byte[] pkcopy = new byte[32];
  byte[] rcopy = new byte[32];
  byte[] scopy = new byte[32];
  byte[] h = new byte[64];
  byte[] rcheck = new byte[32];
  ge_p3 A = new ge_p3();
  ge_p2 R = new ge_p2();

  if (smlen < 64) return -1;
  if ((sm[63] & 224) != 0) return -1;
  if (ge_frombytes.ge_frombytes_negate_vartime(A,pk) != 0) return -1;

  byte[] pubkeyhash = new byte[64];
  sha512provider.calculateDigest(pubkeyhash,pk,32);

  System.arraycopy(pk, 0, pkcopy, 0, 32);
  System.arraycopy(sm, 0, rcopy, 0, 32);
  System.arraycopy(sm, 32, scopy, 0, 32);

  System.arraycopy(sm, 0, m, 0, (int)smlen);
  System.arraycopy(pkcopy, 0, m, 32, 32);
  sha512provider.calculateDigest(h,m,smlen);
  sc_reduce.sc_reduce(h);

  ge_double_scalarmult.ge_double_scalarmult_vartime(R,h,A,scopy);
  ge_tobytes.ge_tobytes(rcheck,R);
  if (crypto_verify_32.crypto_verify_32(rcheck,rcopy) == 0) {
    System.arraycopy(m, 64, m, 0, (int)(smlen - 64));
    //memset(m + smlen - 64,0,64);
    return 0;
  }

//badsig:
  //memset(m,0,smlen);
  return -1;
}
922839
public void remove(SshPublicKey key) throws SshException,
			PublicKeySubsystemException {

		try {

			Packet msg = createPacket();
			msg.writeString("remove");
			msg.writeString(key.getAlgorithm());
			msg.writeBinaryString(key.getEncoded());

			sendMessage(msg);

			readStatusResponse();

		} catch (IOException ex) {
			throw new SshException(ex);
		}
	}
752631
public Blob createEncryptedBlob(String bucketName, String blobName, String encryptionKey) {
    // [START storageUploadEncryptedFile]
    byte[] data = "Hello, World!".getBytes(UTF_8);

    BlobId blobId = BlobId.of(bucketName, blobName);
    BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
    Blob blob = storage.create(blobInfo, data, BlobTargetOption.encryptionKey(encryptionKey));
    // [END storageUploadEncryptedFile]
    return blob;
  }
767771
public static SshPublicKeyFile parse(byte[] formattedkey)
			throws IOException {
		try {
			try {
				return new OpenSSHPublicKeyFile(formattedkey);
			} catch (IOException ex) {
				try {
					return new SECSHPublicKeyFile(formattedkey);
				} catch (IOException ex2) {
					throw new IOException(
							"Unable to parse key, format could not be identified");
				}
			}
		} catch (OutOfMemoryError ex1) {
			throw new IOException(
					"An error occurred parsing a public key file! Is the file corrupt?");
		}
	}
552194
def create_from_request_pdu(pdu):
        
        _, starting_address, quantity, byte_count = \
            struct.unpack('>BHHB', pdu[:6])

        # Values are 16 bit, so each value takes up 2 bytes.
        fmt = '>' + (conf.MULTI_BIT_VALUE_FORMAT_CHARACTER *
                     int((byte_count / 2)))

        values = list(struct.unpack(fmt, pdu[6:]))

        instance = WriteMultipleRegisters()
        instance.starting_address = starting_address
        instance.values = values

        return instance
1360814
def open(cls, blob, username, password):
        """"""
        return cls(blob, blob.encryption_key(username, password))
1256435
public static byte[] HmacSha1(byte[] binaryData, String key) throws Exception {
		try {
			Mac mac = Mac.getInstance(HMAC_SHA1);
			SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1);
			mac.init(secretKey);
			byte[] HmacSha1Digest = mac.doFinal(binaryData);
			return HmacSha1Digest;
			
		} catch (NoSuchAlgorithmException e) {
			LOG.error("mac not find algorithm {}", HMAC_SHA1);
			throw e;
		} catch (InvalidKeyException e) {
			LOG.error("mac init key {} occur a error {}", key, e.toString());
			throw e;
		} catch (IllegalStateException e) {
			LOG.error("mac.doFinal occur a error {}", e.toString());
			throw e;
		}
	}
176284
static byte []
fromPublicKey(PublicKey key, int alg) throws DNSSECException
{
	byte [] data = null;

	switch (alg) {
	case Algorithm.RSAMD5:
	case Algorithm.RSASHA1:
	case Algorithm.RSA_NSEC3_SHA1:
	case Algorithm.RSASHA256:
	case Algorithm.RSASHA512:
		if (! (key instanceof RSAPublicKey))
			throw new IncompatibleKeyException();
		return fromRSAPublicKey((RSAPublicKey) key);
	case Algorithm.DSA:
	case Algorithm.DSA_NSEC3_SHA1:
		if (! (key instanceof DSAPublicKey))
			throw new IncompatibleKeyException();
		return fromDSAPublicKey((DSAPublicKey) key);
	default:
		throw new UnsupportedAlgorithmException(alg);
	}
}
1003017
private void initWithKey(byte[] key) throws SymmetricKeyException {
        if (key == null)
            throw new SymmetricKeyException("Key cannot be null");
        if (key.length != KEY_SIZE)
            throw new SymmetricKeyException("Key size is not " + KEY_SIZE + "bytes");
        keyData = key;
    }
1016954
private static ByteBuf append(ByteBufAllocator allocator, boolean useDirect,
            X509Certificate cert, int count, ByteBuf pem) throws CertificateEncodingException {

        ByteBuf encoded = Unpooled.wrappedBuffer(cert.getEncoded());
        try {
            ByteBuf base64 = SslUtils.toBase64(allocator, encoded);
            try {
                if (pem == null) {
                    // We try to approximate the buffer's initial size. The sizes of
                    // certificates can vary a lot so it'll be off a bit depending
                    // on the number of elements in the array (count argument).
                    pem = newBuffer(allocator, useDirect,
                            (BEGIN_CERT.length + base64.readableBytes() + END_CERT.length) * count);
                }

                pem.writeBytes(BEGIN_CERT);
                pem.writeBytes(base64);
                pem.writeBytes(END_CERT);
            } finally {
                base64.release();
            }
        } finally {
            encoded.release();
        }

        return pem;
    }
809380
def blob(self, nodeid, tag, start=0, end=0xFFFFFFFF):
        
        startkey = self.makekey(nodeid, tag, start)
        endkey = self.makekey(nodeid, tag, end)
        cur = self.btree.find('ge', startkey)
        data = b''
        while cur.getkey() <= endkey:
            data += cur.getval()
            cur.next()
        return data
941636
public static SshKeyPair generateKeyPair(String algorithm, int bits)
			throws IOException, SshException {

		if (!SSH2_RSA.equalsIgnoreCase(algorithm)
				&& !SSH2_DSA.equalsIgnoreCase(algorithm)) {
			throw new IOException(algorithm
					+ " is not a supported key algorithm!");
		}

		SshKeyPair pair = new SshKeyPair();

		if (SSH2_RSA.equalsIgnoreCase(algorithm)) {
			pair = ComponentManager.getInstance().generateRsaKeyPair(bits);
		} else {
			pair = ComponentManager.getInstance().generateDsaKeyPair(bits);
		}

		return pair;
	}
1186102
public static byte[] initKey() throws Exception{
		//密钥生成器
		KeyGenerator keyGen = KeyGenerator.getInstance("AES");
		//初始化密钥生成器
		keyGen.init(128);  //默认128，获得无政策权限后可用192或256
		//生成密钥
		SecretKey secretKey = keyGen.generateKey();
		return secretKey.getEncoded();
	}
1119369
@Override
  int insertBlob(byte[] srcBuffer, int srcRowOffset,
                 byte[] dstBuffer, int dstRowOffset, int dstBlobTail)
  {
    int srcColumnOffset = srcRowOffset + offset();
    int dstColumnOffset = dstRowOffset + offset();
    
    int blobLen = BitsUtil.readInt16(srcBuffer, srcColumnOffset + 2);

    if (blobLen == 0) {
      return dstBlobTail;
    }
    
    blobLen &= ~LARGE_BLOB_MASK;

    if (dstRowOffset < dstBlobTail + blobLen) {
      return -1;
    }

    int blobOffset = BitsUtil.readInt16(srcBuffer, srcColumnOffset);

    try {
      System.arraycopy(srcBuffer, blobOffset, dstBuffer, dstBlobTail,
                       blobLen);
    } catch (ArrayIndexOutOfBoundsException e) {
      throw new ArrayIndexOutOfBoundsException("srcOff: " + blobOffset
                                               + " dstOff: " + dstBlobTail
                                               + " len: " + blobLen
                                               + " " + this);
    }

    BitsUtil.writeInt16(dstBuffer, dstColumnOffset, dstBlobTail);
    
    /*
    System.out.println("SET: " + Hex.toHex(dstBuffer, dstRowOffset, 5) 
                       + " " + Hex.toHex(dstBuffer, dstBlobTail, 4));
                       */
    
    return dstBlobTail + blobLen;
  }
200671
static byte[] hmacSha1(StringBuilder message, String key) {
    try {
      Mac mac = Mac.getInstance("HmacSHA1");
      mac.init(new SecretKeySpec(key.getBytes(), "HmacSHA1"));
      return mac.doFinal(message.toString().getBytes());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }